Skip to content

Commit 9fc49fa

Browse files
committed
fix: /script, testdata and CI support
1 parent 9141187 commit 9fc49fa

File tree

11 files changed

+300
-2
lines changed

11 files changed

+300
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Simple Checks
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: check linenos
15+
run: ./script/check_all_linenos.sh
16+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ __pycache__
6868
rust-analyzer-x86_64-unknown-linux-gnu
6969

7070
testdata/test
71+
testdata/jsons
7172

7273
src/lang/testdata
7374
*.json
7475

75-
tools
76+
tools

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ COZE_BOT_ID={YOUR_COZE_BOT_ID}
7272

7373
2. compile the parsers
7474
```
75-
sh ./script/make_parser.sh
75+
./script/make_parser.sh
7676
```
7777

7878
3. compile and run ABCoder

script/check_all_linenos.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Copyright 2025 CloudWeGo Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
root=$(dirname $(realpath $(dirname $0)))
17+
cd $root
18+
echo "[Making parser]"
19+
./script/make_parser.sh
20+
echo "[Done making parser]"
21+
22+
parser=tools/parser/lang
23+
mkdir -p testdata/jsons
24+
25+
do_test() {
26+
lang=$1
27+
srcpath=$2
28+
name=$3
29+
flags=$4
30+
31+
echo $name...
32+
$parser -d -v --no-need-comment collect $lang $srcpath > testdata/jsons/$name.json 2>testdata/jsons/$name.log
33+
cat $name.log
34+
python script/check_lineno.py --json testdata/jsons/$name.json --base $srcpath $flags > testdata/jsons/$name.check
35+
36+
if grep -q "All functions verified successfully!" testdata/jsons/$name.check; then
37+
echo " [PASS]"
38+
else
39+
echo " [FAIL]"
40+
exit 1
41+
fi
42+
}
43+
do_test go src/lang go "--zero_linebase"
44+
do_test rust testdata/rust2-wobyted rust2 "--zero_linebase --implheads"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""检查 json 中诸符号的 StartOffset, EndOffset, Line, Content 的一致性
2+
(假设本文件在 src/lang 中)
3+
24
例如检查本项目:
35
46
$ ./lang -d -v --no-need-comment collect go . > lang.json

testdata/rust2-wobyted/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "rust2"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
lazy_static = "1.4.0"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::io::{self, Write};
16+
17+
use super::{MyEnum, MyInt, MyInt2, MyStruct, MyTrait};
18+
19+
#[warn(unused_variables)]
20+
pub fn write_to_output<W: Write, T: MyTrait>(
21+
output: &mut W,
22+
input: &T,
23+
arg: &MyStruct,
24+
) -> io::Result<(MyEnum, MyInt2)> {
25+
Ok((MyEnum::A(input.my_trait() + arg.a), arg.b))
26+
}
27+
28+
use core::f64::consts::E;
29+
use std::f32::consts::PI;
30+
31+
fn apply_closure<F, Y: Fn(MyInt) -> MyInt2>(x: Option<MyInt>, func: F, func2: Y) -> MyInt2
32+
where
33+
F: Fn(MyInt) -> MyInt2,
34+
{
35+
func(x.unwrap())
36+
}
37+
38+
/// This is a test function
39+
/// # Example
40+
/// ```
41+
/// let obj = new_obj();
42+
/// ```
43+
pub fn new_obj() -> MyStruct {
44+
MyStruct { a: 1, b: MyInt2(2) }
45+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* Copyright 2025 ByteDance Inc.
17+
*
18+
* Licensed under the Apache License, Version 2.0 (the "License");
19+
* you may not use this file except in compliance with the License.
20+
* You may obtain a copy of the License at
21+
*
22+
* https://www.apache.org/licenses/LICENSE-2.0
23+
*
24+
* Unless required by applicable law or agreed to in writing, software
25+
* distributed under the License is distributed on an "AS IS" BASIS,
26+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27+
* See the License for the specific language governing permissions and
28+
* limitations under the License.
29+
*/
30+
31+
pub trait Addable {
32+
fn id() -> i64;
33+
fn add(&self, b: i64) -> i64;
34+
}
35+
36+
pub struct AnyInt(i64);
37+
38+
impl AnyInt {
39+
pub fn id() -> i64 {
40+
0
41+
}
42+
pub fn add(&self, b: i64) -> i64 {
43+
self.0 + b
44+
}
45+
}
46+
47+
impl Addable for AnyInt {
48+
fn add(&self, b: i64) -> i64 {
49+
// use the method defined in the struct
50+
self.add(b)
51+
}
52+
fn id() -> i64 {
53+
// use the method defined in the struct
54+
AnyInt::id()
55+
}
56+
}
57+
58+
fn add_trait<T: Addable>(i: T, v: i64) {
59+
println!("{}", i.add(v))
60+
}
61+
62+
#[test]
63+
fn test() {
64+
add_trait(AnyInt(1), 2);
65+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
pub type MyInt = i32;
16+
17+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18+
pub struct MyInt2(pub i32);
19+
20+
impl std::ops::Add<MyInt> for MyInt2 {
21+
type Output = MyInt;
22+
23+
fn add(self, rhs: MyInt) -> MyInt {
24+
self.0 + rhs
25+
}
26+
}
27+
28+
pub const MY_INT: MyInt = 42;
29+
30+
pub fn add(a: MyInt, b: MyInt2) -> MyInt {
31+
b + a
32+
}
33+
34+
pub struct MyStruct {
35+
pub a: MyInt,
36+
pub b: MyInt2,
37+
}
38+
39+
impl MyStruct {
40+
pub fn new(a: MyInt, b: MyInt2) -> MyStruct {
41+
MyStruct { a, b }
42+
}
43+
44+
pub fn add(&self) -> MyInt {
45+
self.b + self.a
46+
}
47+
}
48+
49+
trait MyTrait {
50+
fn my_trait(&self) -> MyInt;
51+
}
52+
53+
impl MyTrait for MyStruct {
54+
fn my_trait(&self) -> MyInt {
55+
self.a
56+
}
57+
}
58+
59+
static MY_STATIC: MyInt = 42;
60+
61+
use lazy_static::lazy_static;
62+
63+
lazy_static! {
64+
pub static ref MY_LAZY_STATIC: MyInt = 44;
65+
}
66+
67+
#[derive(Debug)]
68+
pub enum MyEnum {
69+
A(MyInt),
70+
B(MyInt2),
71+
}
72+
73+
#[macro_export]
74+
macro_rules! my_macro {
75+
($e:expr) => {
76+
$e
77+
};
78+
}
79+
80+
pub mod func;
81+
pub mod inter;
82+
83+
lazy_static! {
84+
pub static ref MY_LAZY_STATIC2: MyInt = 45;
85+
}

testdata/rust2-wobyted/src/main.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod entity;
16+
17+
static MY_INT2: u32 = 42;
18+
19+
fn main() {
20+
let a = entity::MyStruct::new(1, entity::MyInt2(2));
21+
println!("{} + {:?} = {}", a.a, a.b, a.add());
22+
let b = entity::add(1, entity::MyInt2(2));
23+
println!("1 + 2 = {}", b);
24+
println!("MY_INT = {}", entity::MY_INT);
25+
println!("MY_INT2 = {}", MY_INT2);
26+
27+
_ = entity::MyEnum::A(1);
28+
_ = entity::MyEnum::B(entity::MyInt2(2));
29+
_ = crate::my_macro!(1);
30+
31+
let mut buf = Vec::new();
32+
entity::func::write_to_output(&mut buf, &a, &a).unwrap();
33+
}

0 commit comments

Comments
 (0)