From 7723d841bfd8058a8cebebb12fc4d75d87923028 Mon Sep 17 00:00:00 2001 From: jakezhu9 Date: Wed, 18 Oct 2023 15:40:51 +0800 Subject: [PATCH 1/4] test: move parser type unit tests to snaptest Signed-off-by: jakezhu9 --- kclvm/parser/src/parser/tests.rs | 190 ------------------ kclvm/parser/src/tests.rs | 24 +++ .../kclvm_parser__tests__types__any_type.snap | 6 + ...vm_parser__tests__types__basic_type_0.snap | 6 + ...vm_parser__tests__types__basic_type_1.snap | 6 + ...vm_parser__tests__types__basic_type_2.snap | 6 + ...vm_parser__tests__types__basic_type_3.snap | 6 + ...lvm_parser__tests__types__dict_type_0.snap | 6 + ...lvm_parser__tests__types__dict_type_1.snap | 6 + ...lvm_parser__tests__types__dict_type_2.snap | 6 + ...lvm_parser__tests__types__dict_type_3.snap | 6 + ...lvm_parser__tests__types__dict_type_4.snap | 6 + ...lvm_parser__tests__types__list_type_0.snap | 6 + ...lvm_parser__tests__types__list_type_1.snap | 6 + ...lvm_parser__tests__types__list_type_2.snap | 6 + ...lvm_parser__tests__types__list_type_3.snap | 6 + ...lvm_parser__tests__types__list_type_4.snap | 6 + ..._parser__tests__types__literal_type_0.snap | 6 + ..._parser__tests__types__literal_type_1.snap | 6 + ..._parser__tests__types__literal_type_2.snap | 6 + ..._parser__tests__types__literal_type_3.snap | 6 + ..._parser__tests__types__literal_type_4.snap | 6 + ..._parser__tests__types__literal_type_5.snap | 6 + ...vm_parser__tests__types__named_type_0.snap | 6 + ...vm_parser__tests__types__named_type_1.snap | 6 + ...vm_parser__tests__types__union_type_0.snap | 6 + ...vm_parser__tests__types__union_type_1.snap | 6 + kclvm/parser/src/tests/types.rs | 27 +++ 28 files changed, 201 insertions(+), 190 deletions(-) create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__any_type.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_2.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_3.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_2.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_3.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_4.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_2.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_3.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_4.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_2.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_3.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_4.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_5.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_1.snap create mode 100644 kclvm/parser/src/tests/types.rs diff --git a/kclvm/parser/src/parser/tests.rs b/kclvm/parser/src/parser/tests.rs index 907cdb58b..eaa5d7840 100644 --- a/kclvm/parser/src/parser/tests.rs +++ b/kclvm/parser/src/parser/tests.rs @@ -22,20 +22,6 @@ fn check_parsing_file_ast_json(filename: &str, src: &str, expect: Expect) { expect.assert_eq(&actual) } -fn check_parsing_type(src: &str, expect: Expect) { - let sm = SourceMap::new(FilePathMapping::empty()); - sm.new_source_file(PathBuf::from("").into(), src.to_string()); - let sess = &ParseSession::with_source_map(Arc::new(sm)); - - create_session_globals_then(|| { - let stream = parse_token_streams(sess, src, new_byte_pos(0)); - let mut parser = Parser::new(sess, stream); - let typ = parser.parse_type_annotation(); - let actual = format!("{typ:?}\n"); - expect.assert_eq(&actual) - }); -} - fn check_type_str(src: &str, expect: Expect) { let sm = SourceMap::new(FilePathMapping::empty()); sm.new_source_file(PathBuf::from("").into(), src.to_string()); @@ -56,182 +42,6 @@ fn check_parsing_module(filename: &str, src: &str, expect: &str) { assert_eq!(actual.trim(), expect.trim()); } -#[test] -fn test_basic_type() { - check_parsing_type( - r####"bool"####, - expect![[r#" - Node { node: Basic(Bool), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ); - check_parsing_type( - r####"int"####, - expect![[r#" - Node { node: Basic(Int), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } - "#]], - ); - check_parsing_type( - r####"float"####, - expect![[r#" - Node { node: Basic(Float), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); - check_parsing_type( - r####"str"####, - expect![[r#" - Node { node: Basic(Str), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } - "#]], - ); -} - -#[test] -fn test_any_type() { - check_parsing_type( - r####"any"####, - expect![[r#" - Node { node: Any, filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } - "#]], - ); -} - -#[test] -fn test_list_type() { - check_parsing_type( - r####"[]"####, - expect![[r#" - Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 2 } - "#]], - ); - check_parsing_type( - r####"[int]"####, - expect![[r#" - Node { node: List(ListType { inner_type: Some(Node { node: Basic(Int), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); - check_parsing_type( - r####"[any]"####, - expect![[r#" - Node { node: List(ListType { inner_type: Some(Node { node: Any, filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); - - check_parsing_type( - r####"[[]]"####, - expect![[r#" - Node { node: List(ListType { inner_type: Some(Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 1, end_line: 1, end_column: 3 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ); - check_parsing_type( - r####"[[str]]"####, - expect![[r#" - Node { node: List(ListType { inner_type: Some(Node { node: List(ListType { inner_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 2, end_line: 1, end_column: 5 }) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); -} - -#[test] -fn test_dict_type() { - check_parsing_type( - r####"{:}"####, - expect![[r#" - Node { node: Dict(DictType { key_type: None, value_type: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } - "#]], - ); - check_parsing_type( - r####"{str:}"####, - expect![[r#" - Node { node: Dict(DictType { key_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }), value_type: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); - check_parsing_type( - r####"{:[]}"####, - expect![[r#" - Node { node: Dict(DictType { key_type: None, value_type: Some(Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 2, end_line: 1, end_column: 4 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); - check_parsing_type( - r####"{str:{:float}}"####, - expect![[r#" - Node { node: Dict(DictType { key_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }), value_type: Some(Node { node: Dict(DictType { key_type: None, value_type: Some(Node { node: Basic(Float), filename: "", line: 1, column: 7, end_line: 1, end_column: 12 }) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 13 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } - "#]], - ); -} - -#[test] -fn test_union_type() { - check_parsing_type( - r####"int|str"####, - expect![[r#" - Node { node: Union(UnionType { type_elements: [Node { node: Basic(Int), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, Node { node: Basic(Str), filename: "", line: 1, column: 4, end_line: 1, end_column: 7 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } - "#]], - ); - check_parsing_type( - r####"int | str | [] | {:}"####, - expect![[r#" - Node { node: Union(UnionType { type_elements: [Node { node: Basic(Int), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, Node { node: Basic(Str), filename: "", line: 1, column: 6, end_line: 1, end_column: 9 }, Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 12, end_line: 1, end_column: 14 }, Node { node: Dict(DictType { key_type: None, value_type: None }), filename: "", line: 1, column: 17, end_line: 1, end_column: 20 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 20 } - "#]], - ); -} - -#[test] -fn test_named_type() { - check_parsing_type( - r####"Person"####, - expect![[r#" - Node { node: Named(Identifier { names: [Node { node: "Person", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } - "#]], - ); - check_parsing_type( - r####"some.pkg.Person"####, - expect![[r#" - Node { node: Named(Identifier { names: [Node { node: "some", filename: "", line: 1, column: 0, end_line: 1, end_column: 4 }, Node { node: "pkg", filename: "", line: 1, column: 5, end_line: 1, end_column: 8 }, Node { node: "Person", filename: "", line: 1, column: 9, end_line: 1, end_column: 15 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 15 } - "#]], - ) -} - -#[test] -fn test_literal_type() { - check_parsing_type( - r####"True"####, - expect![[r#" - Node { node: Literal(Bool(true)), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } - "#]], - ); - check_parsing_type( - r####" False "####, - expect![[r#" - Node { node: Literal(Bool(false)), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 } - "#]], - ); - - check_parsing_type( - r####"123"####, - expect![[r#" - Node { node: Literal(Int(123, None)), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } - "#]], - ); - - check_parsing_type( - r####"123.0"####, - expect![[r#" - Node { node: Literal(Float(123.0)), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); - - check_parsing_type( - r####""abc""####, - expect![[r#" - Node { node: Literal(Str("abc")), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } - "#]], - ); - check_parsing_type( - r####"''"####, - expect![[r#" - Node { node: Literal(Str("")), filename: "", line: 1, column: 0, end_line: 1, end_column: 2 } - "#]], - ); -} - #[test] fn test_type_str() { check_type_str(r####"int"####, expect![[r#"int"#]]); diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index 09b31b1cd..2143f62da 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -12,6 +12,7 @@ use core::any::Any; mod error_recovery; mod expr; +mod types; #[macro_export] macro_rules! parse_expr_snapshot { @@ -33,6 +34,16 @@ macro_rules! parse_module_snapshot { }; } +#[macro_export] +macro_rules! parse_type_snapshot { + ($name:ident, $src:expr) => { + #[test] + fn $name() { + insta::assert_snapshot!($crate::tests::parsing_type_string($src)); + } + }; +} + pub(crate) fn parsing_expr_string(src: &str) -> String { let sm = SourceMap::new(FilePathMapping::empty()); let sf = sm.new_source_file(PathBuf::from("").into(), src.to_string()); @@ -65,6 +76,19 @@ pub(crate) fn parsing_module_string(src: &str) -> String { } } +pub(crate) fn parsing_type_string(src: &str) -> String { + let sm = SourceMap::new(FilePathMapping::empty()); + sm.new_source_file(PathBuf::from("").into(), src.to_string()); + let sess = &ParseSession::with_source_map(Arc::new(sm)); + + create_session_globals_then(|| { + let stream = parse_token_streams(sess, src, new_byte_pos(0)); + let mut parser = Parser::new(sess, stream); + let typ = parser.parse_type_annotation(); + format!("{typ:?}\n") + }) +} + pub fn check_result_panic_info(result: Result<(), Box>) { if let Err(e) = result { assert!(e.downcast::().is_ok()); diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__any_type.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__any_type.snap new file mode 100644 index 000000000..82c85bae7 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__any_type.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"any\"####)" +--- +Node { node: Any, filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_0.snap new file mode 100644 index 000000000..0278843ab --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_0.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"bool\"####)" +--- +Node { node: Basic(Bool), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_1.snap new file mode 100644 index 000000000..a1e2bf120 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_1.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"int\"####)" +--- +Node { node: Basic(Int), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_2.snap new file mode 100644 index 000000000..050eeed43 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_2.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"float\"####)" +--- +Node { node: Basic(Float), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_3.snap new file mode 100644 index 000000000..36be5555c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__basic_type_3.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"str\"####)" +--- +Node { node: Basic(Str), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_0.snap new file mode 100644 index 000000000..7ee365471 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_0.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"{:}\"####)" +--- +Node { node: Dict(DictType { key_type: None, value_type: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_1.snap new file mode 100644 index 000000000..4c8cc46fb --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_1.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"{str:}\"####)" +--- +Node { node: Dict(DictType { key_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }), value_type: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_2.snap new file mode 100644 index 000000000..d60382838 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_2.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"{:[]}\"####)" +--- +Node { node: Dict(DictType { key_type: None, value_type: Some(Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 2, end_line: 1, end_column: 4 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_3.snap new file mode 100644 index 000000000..f7a89090d --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_3.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"{str:{:float}}\"####)" +--- +Node { node: Dict(DictType { key_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }), value_type: Some(Node { node: Dict(DictType { key_type: None, value_type: Some(Node { node: Basic(Float), filename: "", line: 1, column: 7, end_line: 1, end_column: 12 }) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 13 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_4.snap new file mode 100644 index 000000000..3529c1f71 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__dict_type_4.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"{str:{:float}, int:[]}\"####)" +--- +Node { node: Dict(DictType { key_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }), value_type: Some(Node { node: Dict(DictType { key_type: None, value_type: Some(Node { node: Basic(Float), filename: "", line: 1, column: 7, end_line: 1, end_column: 12 }) }), filename: "", line: 1, column: 5, end_line: 1, end_column: 13 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 14 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_0.snap new file mode 100644 index 000000000..92d5a957d --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_0.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"[]\"####)" +--- +Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 0, end_line: 1, end_column: 2 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_1.snap new file mode 100644 index 000000000..f5953cbcf --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_1.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"[int]\"####)" +--- +Node { node: List(ListType { inner_type: Some(Node { node: Basic(Int), filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_2.snap new file mode 100644 index 000000000..3d65a2b95 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_2.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"[any]\"####)" +--- +Node { node: List(ListType { inner_type: Some(Node { node: Any, filename: "", line: 1, column: 1, end_line: 1, end_column: 4 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_3.snap new file mode 100644 index 000000000..b8179378e --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_3.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"[[]]\"####)" +--- +Node { node: List(ListType { inner_type: Some(Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 1, end_line: 1, end_column: 3 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_4.snap new file mode 100644 index 000000000..6be62054b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__list_type_4.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"[[str]]\"####)" +--- +Node { node: List(ListType { inner_type: Some(Node { node: List(ListType { inner_type: Some(Node { node: Basic(Str), filename: "", line: 1, column: 2, end_line: 1, end_column: 5 }) }), filename: "", line: 1, column: 1, end_line: 1, end_column: 6 }) }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_0.snap new file mode 100644 index 000000000..4e96bc209 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_0.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"True\"####)" +--- +Node { node: Literal(Bool(true)), filename: "", line: 1, column: 0, end_line: 1, end_column: 4 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_1.snap new file mode 100644 index 000000000..1ea1a4aaa --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_1.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"False\"####)" +--- +Node { node: Literal(Bool(false)), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_2.snap new file mode 100644 index 000000000..412c2daa5 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_2.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"123\"####)" +--- +Node { node: Literal(Int(123, None)), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_3.snap new file mode 100644 index 000000000..d70e4b2ce --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_3.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"123.0\"####)" +--- +Node { node: Literal(Float(123.0)), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_4.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_4.snap new file mode 100644 index 000000000..8b5bbed08 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_4.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"\"abc\"\"####)" +--- +Node { node: Literal(Str("abc")), filename: "", line: 1, column: 0, end_line: 1, end_column: 5 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_5.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_5.snap new file mode 100644 index 000000000..c6e30c431 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__literal_type_5.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"''\"####)" +--- +Node { node: Literal(Str("")), filename: "", line: 1, column: 0, end_line: 1, end_column: 2 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_0.snap new file mode 100644 index 000000000..a2a929e53 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_0.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"Person\"####)" +--- +Node { node: Named(Identifier { names: [Node { node: "Person", filename: "", line: 1, column: 0, end_line: 1, end_column: 6 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 6 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_1.snap new file mode 100644 index 000000000..2552edc9b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__named_type_1.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"some.pkg.Person\"####)" +--- +Node { node: Named(Identifier { names: [Node { node: "some", filename: "", line: 1, column: 0, end_line: 1, end_column: 4 }, Node { node: "pkg", filename: "", line: 1, column: 5, end_line: 1, end_column: 8 }, Node { node: "Person", filename: "", line: 1, column: 9, end_line: 1, end_column: 15 }], pkgpath: "", ctx: Load }), filename: "", line: 1, column: 0, end_line: 1, end_column: 15 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_0.snap new file mode 100644 index 000000000..89a015a32 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_0.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"int|str\"####)" +--- +Node { node: Union(UnionType { type_elements: [Node { node: Basic(Int), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, Node { node: Basic(Str), filename: "", line: 1, column: 4, end_line: 1, end_column: 7 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 7 } + diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_1.snap new file mode 100644 index 000000000..040a35f0c --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__union_type_1.snap @@ -0,0 +1,6 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_string(r####\"int | str | [] | {:}\"####)" +--- +Node { node: Union(UnionType { type_elements: [Node { node: Basic(Int), filename: "", line: 1, column: 0, end_line: 1, end_column: 3 }, Node { node: Basic(Str), filename: "", line: 1, column: 6, end_line: 1, end_column: 9 }, Node { node: List(ListType { inner_type: None }), filename: "", line: 1, column: 12, end_line: 1, end_column: 14 }, Node { node: Dict(DictType { key_type: None, value_type: None }), filename: "", line: 1, column: 17, end_line: 1, end_column: 20 }] }), filename: "", line: 1, column: 0, end_line: 1, end_column: 20 } + diff --git a/kclvm/parser/src/tests/types.rs b/kclvm/parser/src/tests/types.rs new file mode 100644 index 000000000..541bdd05b --- /dev/null +++ b/kclvm/parser/src/tests/types.rs @@ -0,0 +1,27 @@ +use crate::tests::parse_type_snapshot; + +parse_type_snapshot!(basic_type_0, r####"bool"####); +parse_type_snapshot!(basic_type_1, r####"int"####); +parse_type_snapshot!(basic_type_2, r####"float"####); +parse_type_snapshot!(basic_type_3, r####"str"####); +parse_type_snapshot!(any_type, r####"any"####); +parse_type_snapshot!(list_type_0, r####"[]"####); +parse_type_snapshot!(list_type_1, r####"[int]"####); +parse_type_snapshot!(list_type_2, r####"[any]"####); +parse_type_snapshot!(list_type_3, r####"[[]]"####); +parse_type_snapshot!(list_type_4, r####"[[str]]"####); +parse_type_snapshot!(dict_type_0, r####"{:}"####); +parse_type_snapshot!(dict_type_1, r####"{str:}"####); +parse_type_snapshot!(dict_type_2, r####"{:[]}"####); +parse_type_snapshot!(dict_type_3, r####"{str:{:float}}"####); +parse_type_snapshot!(dict_type_4, r####"{str:{:float}, int:[]}"####); +parse_type_snapshot!(union_type_0, r####"int|str"####); +parse_type_snapshot!(union_type_1, r####"int | str | [] | {:}"####); +parse_type_snapshot!(named_type_0, r####"Person"####); +parse_type_snapshot!(named_type_1, r####"some.pkg.Person"####); +parse_type_snapshot!(literal_type_0, r####"True"####); +parse_type_snapshot!(literal_type_1, r####"False"####); +parse_type_snapshot!(literal_type_2, r####"123"####); +parse_type_snapshot!(literal_type_3, r####"123.0"####); +parse_type_snapshot!(literal_type_4, r####""abc""####); +parse_type_snapshot!(literal_type_5, r####"''"####); From 1119a7e3f19e542fefebc1ed9d5c7129e4e55f42 Mon Sep 17 00:00:00 2001 From: jakezhu9 Date: Wed, 18 Oct 2023 16:00:08 +0800 Subject: [PATCH 2/4] test: move parser type node unit tests to snaptest Signed-off-by: jakezhu9 --- kclvm/parser/src/parser/tests.rs | 35 ------------------- kclvm/parser/src/tests.rs | 23 ++++++++++++ ...clvm_parser__tests__types__type_str_0.snap | 5 +++ ...clvm_parser__tests__types__type_str_1.snap | 5 +++ ...clvm_parser__tests__types__type_str_2.snap | 5 +++ ...clvm_parser__tests__types__type_str_3.snap | 5 +++ kclvm/parser/src/tests/types.rs | 7 +++- 7 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_2.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_3.snap diff --git a/kclvm/parser/src/parser/tests.rs b/kclvm/parser/src/parser/tests.rs index eaa5d7840..9dd914074 100644 --- a/kclvm/parser/src/parser/tests.rs +++ b/kclvm/parser/src/parser/tests.rs @@ -1,13 +1,7 @@ -use crate::lexer::parse_token_streams; use crate::parse_file; -use crate::parser::Parser; use crate::session::ParseSession; -use compiler_base_span::span::new_byte_pos; -use compiler_base_span::{FilePathMapping, SourceMap}; use expect_test::{expect, Expect}; -use kclvm_span::create_session_globals_then; use regex::Regex; -use std::path::PathBuf; use std::sync::Arc; fn check_parsing_file_ast_json(filename: &str, src: &str, expect: Expect) { @@ -22,41 +16,12 @@ fn check_parsing_file_ast_json(filename: &str, src: &str, expect: Expect) { expect.assert_eq(&actual) } -fn check_type_str(src: &str, expect: Expect) { - let sm = SourceMap::new(FilePathMapping::empty()); - sm.new_source_file(PathBuf::from("").into(), src.to_string()); - let sess = &ParseSession::with_source_map(Arc::new(sm)); - - create_session_globals_then(|| { - let stream = parse_token_streams(sess, src, new_byte_pos(0)); - let mut parser = Parser::new(sess, stream); - let typ = parser.parse_type_annotation(); - let actual = typ.node.to_string(); - expect.assert_eq(&actual) - }); -} - fn check_parsing_module(filename: &str, src: &str, expect: &str) { let m = crate::parse_file(filename, Some(src.to_string())).expect(filename); let actual = format!("{}\n", serde_json::ser::to_string(&m).unwrap()); assert_eq!(actual.trim(), expect.trim()); } -#[test] -fn test_type_str() { - check_type_str(r####"int"####, expect![[r#"int"#]]); - check_type_str(r####" int "####, expect![[r#"int"#]]); - - check_type_str( - r####"bool | True | int | str|str"####, - expect![[r#"bool | True | int | str | str"#]], - ); - check_type_str( - r####"[ [{str: float}] | int]"####, - expect![[r#"[[{str:float}] | int]"#]], - ); -} - #[test] fn test_parse_schema_stmt() { check_parsing_file_ast_json( diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index 2143f62da..62f53a698 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -44,6 +44,16 @@ macro_rules! parse_type_snapshot { }; } +#[macro_export] +macro_rules! parse_type_node_snapshot { + ($name:ident, $src:expr) => { + #[test] + fn $name() { + insta::assert_snapshot!($crate::tests::parsing_type_node_string($src)); + } + }; +} + pub(crate) fn parsing_expr_string(src: &str) -> String { let sm = SourceMap::new(FilePathMapping::empty()); let sf = sm.new_source_file(PathBuf::from("").into(), src.to_string()); @@ -89,6 +99,19 @@ pub(crate) fn parsing_type_string(src: &str) -> String { }) } +pub(crate) fn parsing_type_node_string(src: &str) -> String { + let sm = SourceMap::new(FilePathMapping::empty()); + sm.new_source_file(PathBuf::from("").into(), src.to_string()); + let sess = &ParseSession::with_source_map(Arc::new(sm)); + + create_session_globals_then(|| { + let stream = parse_token_streams(sess, src, new_byte_pos(0)); + let mut parser = Parser::new(sess, stream); + let typ = parser.parse_type_annotation(); + typ.node.to_string() + }) +} + pub fn check_result_panic_info(result: Result<(), Box>) { if let Err(e) = result { assert!(e.downcast::().is_ok()); diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_0.snap new file mode 100644 index 000000000..fe487c4ab --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_0.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_node_string(r####\"int\"####)" +--- +int diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_1.snap new file mode 100644 index 000000000..b5d050c86 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_1.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_node_string(r####\" int \"####)" +--- +int diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_2.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_2.snap new file mode 100644 index 000000000..f6ceb4f04 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_2.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_node_string(r####\"bool | True | int | str|str\"####)" +--- +bool | True | int | str | str diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_3.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_3.snap new file mode 100644 index 000000000..8d25e81de --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__types__type_str_3.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/types.rs +expression: "crate::tests::parsing_type_node_string(r####\"[ [{str: float}] | int]\"####)" +--- +[[{str:float}] | int] diff --git a/kclvm/parser/src/tests/types.rs b/kclvm/parser/src/tests/types.rs index 541bdd05b..d1b2ab629 100644 --- a/kclvm/parser/src/tests/types.rs +++ b/kclvm/parser/src/tests/types.rs @@ -1,4 +1,4 @@ -use crate::tests::parse_type_snapshot; +use crate::tests::{parse_type_node_snapshot, parse_type_snapshot}; parse_type_snapshot!(basic_type_0, r####"bool"####); parse_type_snapshot!(basic_type_1, r####"int"####); @@ -25,3 +25,8 @@ parse_type_snapshot!(literal_type_2, r####"123"####); parse_type_snapshot!(literal_type_3, r####"123.0"####); parse_type_snapshot!(literal_type_4, r####""abc""####); parse_type_snapshot!(literal_type_5, r####"''"####); + +parse_type_node_snapshot!(type_str_0, r####"int"####); +parse_type_node_snapshot!(type_str_1, r####" int "####); +parse_type_node_snapshot!(type_str_2, r####"bool | True | int | str|str"####); +parse_type_node_snapshot!(type_str_3, r####"[ [{str: float}] | int]"####); From 4876dcec3cb581b612fe6f835a8f06ff6e9c5b1c Mon Sep 17 00:00:00 2001 From: jakezhu9 Date: Wed, 18 Oct 2023 16:03:48 +0800 Subject: [PATCH 3/4] test: move parser ast json unit tests to snaptest Signed-off-by: jakezhu9 --- kclvm/parser/src/parser/tests.rs | 111 ------------------ kclvm/parser/src/tests.rs | 21 ++++ kclvm/parser/src/tests/ast.rs | 70 +++++++++++ ...kclvm_parser__tests__ast__assign_stmt.snap | 5 + .../kclvm_parser__tests__ast__basic_stmt.snap | 5 + .../kclvm_parser__tests__ast__if_stmt_0.snap | 5 + .../kclvm_parser__tests__ast__if_stmt_1.snap | 5 + ...kclvm_parser__tests__ast__schema_stmt.snap | 5 + 8 files changed, 116 insertions(+), 111 deletions(-) create mode 100644 kclvm/parser/src/tests/ast.rs create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap diff --git a/kclvm/parser/src/parser/tests.rs b/kclvm/parser/src/parser/tests.rs index 9dd914074..46f2251ef 100644 --- a/kclvm/parser/src/parser/tests.rs +++ b/kclvm/parser/src/parser/tests.rs @@ -1,20 +1,5 @@ use crate::parse_file; -use crate::session::ParseSession; -use expect_test::{expect, Expect}; use regex::Regex; -use std::sync::Arc; - -fn check_parsing_file_ast_json(filename: &str, src: &str, expect: Expect) { - let m = crate::parse_file_with_global_session( - Arc::new(ParseSession::default()), - filename, - Some(src.into()), - ) - .unwrap(); - let actual = serde_json::ser::to_string(&m).unwrap(); - let actual = format!("{actual}\n"); - expect.assert_eq(&actual) -} fn check_parsing_module(filename: &str, src: &str, expect: &str) { let m = crate::parse_file(filename, Some(src.to_string())).expect(filename); @@ -22,102 +7,6 @@ fn check_parsing_module(filename: &str, src: &str, expect: &str) { assert_eq!(actual.trim(), expect.trim()); } -#[test] -fn test_parse_schema_stmt() { - check_parsing_file_ast_json( - "hello.k", - r####" -schema TestBool: - [] - [str ]: int - [a: str]: int - [a: ...str]: int - [...str]: int - a: int - b?: str - c: int = 0 - d?: str = "" - - [a] - [a, b, c] - [ - 1 - ] - [ - a - ] - [a for a in [1, 2, 3]] - [ - a for a in [1, 2, 3] - ] - - check: - a > 1, "msg" - name not None, "we fail here" - "####, - expect![[r#" - {"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"TestBool","filename":"hello.k","line":2,"column":7,"end_line":2,"end_column":15},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[],"ctx":"Load"}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6}]}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6},{"node":{"SchemaAttr":{"doc":"","name":{"node":"a","filename":"hello.k","line":8,"column":4,"end_line":8,"end_column":5},"type_str":{"node":"int","filename":"hello.k","line":8,"column":7,"end_line":8,"end_column":10},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":8,"column":7,"end_line":8,"end_column":10}}},"filename":"hello.k","line":8,"column":4,"end_line":8,"end_column":10},{"node":{"SchemaAttr":{"doc":"","name":{"node":"b","filename":"hello.k","line":9,"column":4,"end_line":9,"end_column":5},"type_str":{"node":"str","filename":"hello.k","line":9,"column":8,"end_line":9,"end_column":11},"op":null,"value":null,"is_optional":true,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":9,"column":8,"end_line":9,"end_column":11}}},"filename":"hello.k","line":9,"column":4,"end_line":10,"end_column":0},{"node":{"SchemaAttr":{"doc":"","name":{"node":"c","filename":"hello.k","line":10,"column":4,"end_line":10,"end_column":5},"type_str":{"node":"int","filename":"hello.k","line":10,"column":7,"end_line":10,"end_column":10},"op":{"Aug":"Assign"},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":0}}},"filename":"hello.k","line":10,"column":13,"end_line":10,"end_column":14},"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":10,"column":7,"end_line":10,"end_column":10}}},"filename":"hello.k","line":10,"column":4,"end_line":10,"end_column":14},{"node":{"SchemaAttr":{"doc":"","name":{"node":"d","filename":"hello.k","line":11,"column":4,"end_line":11,"end_column":5},"type_str":{"node":"str","filename":"hello.k","line":11,"column":8,"end_line":11,"end_column":11},"op":{"Aug":"Assign"},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"\"","value":""}},"filename":"hello.k","line":11,"column":14,"end_line":11,"end_column":16},"is_optional":true,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":11,"column":8,"end_line":11,"end_column":11}}},"filename":"hello.k","line":11,"column":4,"end_line":13,"end_column":0},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":13,"column":5,"end_line":13,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":13,"column":5,"end_line":13,"end_column":6}],"ctx":"Load"}},"filename":"hello.k","line":13,"column":4,"end_line":13,"end_column":7}]}},"filename":"hello.k","line":13,"column":4,"end_line":13,"end_column":7},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":14,"column":5,"end_line":14,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":5,"end_line":14,"end_column":6},{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":14,"column":8,"end_line":14,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":8,"end_line":14,"end_column":9},{"node":{"Identifier":{"names":[{"node":"c","filename":"hello.k","line":14,"column":11,"end_line":14,"end_column":12}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":11,"end_line":14,"end_column":12}],"ctx":"Load"}},"filename":"hello.k","line":14,"column":4,"end_line":14,"end_column":13}]}},"filename":"hello.k","line":14,"column":4,"end_line":14,"end_column":13},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":16,"column":8,"end_line":16,"end_column":9}],"ctx":"Load"}},"filename":"hello.k","line":15,"column":4,"end_line":17,"end_column":5}]}},"filename":"hello.k","line":15,"column":4,"end_line":17,"end_column":5},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":19,"column":8,"end_line":19,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":19,"column":8,"end_line":19,"end_column":9}],"ctx":"Load"}},"filename":"hello.k","line":18,"column":4,"end_line":20,"end_column":5}]}},"filename":"hello.k","line":18,"column":4,"end_line":20,"end_column":5},{"node":{"Expr":{"exprs":[{"node":{"ListComp":{"elt":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":21,"column":5,"end_line":21,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":21,"column":5,"end_line":21,"end_column":6},"generators":[{"node":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":21,"column":11,"end_line":21,"end_column":12}],"pkgpath":"","ctx":"Load"},"filename":"hello.k","line":21,"column":11,"end_line":21,"end_column":12}],"iter":{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":21,"column":17,"end_line":21,"end_column":18},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":21,"column":20,"end_line":21,"end_column":21},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":21,"column":23,"end_line":21,"end_column":24}],"ctx":"Load"}},"filename":"hello.k","line":21,"column":16,"end_line":21,"end_column":25},"ifs":[]},"filename":"hello.k","line":21,"column":7,"end_line":21,"end_column":25}]}},"filename":"hello.k","line":21,"column":4,"end_line":21,"end_column":26}]}},"filename":"hello.k","line":21,"column":4,"end_line":21,"end_column":26},{"node":{"Expr":{"exprs":[{"node":{"ListComp":{"elt":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":23,"column":8,"end_line":23,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":23,"column":8,"end_line":23,"end_column":9},"generators":[{"node":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":23,"column":14,"end_line":23,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"hello.k","line":23,"column":14,"end_line":23,"end_column":15}],"iter":{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":23,"column":20,"end_line":23,"end_column":21},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":23,"column":23,"end_line":23,"end_column":24},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":23,"column":26,"end_line":23,"end_column":27}],"ctx":"Load"}},"filename":"hello.k","line":23,"column":19,"end_line":23,"end_column":28},"ifs":[]},"filename":"hello.k","line":23,"column":10,"end_line":24,"end_column":0}]}},"filename":"hello.k","line":22,"column":4,"end_line":24,"end_column":5}]}},"filename":"hello.k","line":22,"column":4,"end_line":24,"end_column":5}],"decorators":[],"checks":[{"node":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":9},"ops":["Gt"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":27,"column":12,"end_line":27,"end_column":13}]}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":13},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"msg\"","value":"msg"}},"filename":"hello.k","line":27,"column":15,"end_line":27,"end_column":20}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":20},{"node":{"test":{"node":{"Identifier":{"names":[{"node":"name","filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12},"if_cond":null,"msg":null},"filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12},{"node":{"test":{"node":{"Unary":{"op":"Not","operand":{"node":{"NameConstantLit":{"value":"None"}},"filename":"hello.k","line":28,"column":17,"end_line":28,"end_column":21}}},"filename":"hello.k","line":28,"column":13,"end_line":28,"end_column":21},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"we fail here\"","value":"we fail here"}},"filename":"hello.k","line":28,"column":23,"end_line":28,"end_column":37}},"filename":"hello.k","line":28,"column":13,"end_line":28,"end_column":37}],"index_signature":{"node":{"key_name":null,"key_type":{"node":"str","filename":"hello.k","line":7,"column":8,"end_line":7,"end_column":11},"value_type":{"node":"int","filename":"hello.k","line":7,"column":14,"end_line":7,"end_column":17},"value":null,"any_other":true,"value_ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":7,"column":14,"end_line":7,"end_column":17}},"filename":"hello.k","line":7,"column":4,"end_line":8,"end_column":0}}},"filename":"hello.k","line":2,"column":0,"end_line":29,"end_column":8}],"comments":[]} - "#]], - ); -} - -#[test] -fn test_parse_assign_stmt() { - check_parsing_file_ast_json( - "hello.k", - r####"a=123"####, - expect![[r#" - {"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":123}}},"filename":"hello.k","line":1,"column":2,"end_line":1,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":5}],"comments":[]} - "#]], - ); -} - -#[test] -fn test_parse_if_stmt() { - check_parsing_file_ast_json( - "hello.k", - r####" -a = 10 -b = 12 -_condition = 0 -if a == 11 or b == 13: _condition = 1 -elif a == 10 and b == 12: _condition = 2 -condition = _condition - "####, - expect![[r#" - {"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"hello.k","line":2,"column":4,"end_line":2,"end_column":6},"type_annotation":null,"ty":null}},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":6},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":12}}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6},"type_annotation":null,"ty":null}},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":6},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":10}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":10}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":0}}},"filename":"hello.k","line":4,"column":13,"end_line":4,"end_column":14},"type_annotation":null,"ty":null}},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":14},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":33}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":33}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":5,"column":36,"end_line":5,"end_column":37},"type_annotation":null,"ty":null}},"filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":37}],"cond":{"node":{"Binary":{"left":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":4},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":11}}},"filename":"hello.k","line":5,"column":8,"end_line":5,"end_column":10}]}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":21},"op":{"Bin":"Or"},"right":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":15}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":15},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":13}}},"filename":"hello.k","line":5,"column":19,"end_line":5,"end_column":21}]}},"filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":21}}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":21},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":36}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":36}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":6,"column":39,"end_line":6,"end_column":40},"type_annotation":null,"ty":null}},"filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":40}],"cond":{"node":{"Binary":{"left":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":6},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"hello.k","line":6,"column":10,"end_line":6,"end_column":12}]}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":24},"op":{"Bin":"And"},"right":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":18}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":18},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":12}}},"filename":"hello.k","line":6,"column":22,"end_line":6,"end_column":24}]}},"filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":24}}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":24},"orelse":[]}},"filename":"hello.k","line":6,"column":0,"end_line":7,"end_column":0}]}},"filename":"hello.k","line":5,"column":0,"end_line":7,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"condition","filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":9}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":9}],"value":{"node":{"Identifier":{"names":[{"node":"_condition","filename":"hello.k","line":7,"column":12,"end_line":7,"end_column":22}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":7,"column":12,"end_line":7,"end_column":22},"type_annotation":null,"ty":null}},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":22}],"comments":[]} - "#]], - ); - - check_parsing_file_ast_json( - "hello.k", - r####" -data2 = { - **{key = "value1"} - if a == 123: if b == 456: key = "value2" -} - "####, - expect![[r#" - {"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"data2","filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":5}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":5}],"value":{"node":{"Config":{"items":[{"node":{"key":null,"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"key","filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":10}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":10},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"value1\"","value":"value1"}},"filename":"hello.k","line":3,"column":13,"end_line":3,"end_column":21},"operation":"Override","insert_index":-1},"filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":21}]}},"filename":"hello.k","line":3,"column":6,"end_line":3,"end_column":22},"operation":"Union","insert_index":-1},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":22},{"node":{"key":null,"value":{"node":{"ConfigIfEntry":{"if_cond":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":123}}},"filename":"hello.k","line":4,"column":12,"end_line":4,"end_column":15}]}},"filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":15},"items":[{"node":{"key":null,"value":{"node":{"ConfigIfEntry":{"if_cond":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":21}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":21},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":456}}},"filename":"hello.k","line":4,"column":25,"end_line":4,"end_column":28}]}},"filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":28},"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"key","filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"value2\"","value":"value2"}},"filename":"hello.k","line":4,"column":36,"end_line":4,"end_column":44},"operation":"Override","insert_index":-1},"filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":44}],"orelse":null}},"filename":"hello.k","line":4,"column":17,"end_line":5,"end_column":0},"operation":"Override","insert_index":-1},"filename":"hello.k","line":4,"column":17,"end_line":5,"end_column":0}],"orelse":null}},"filename":"hello.k","line":4,"column":4,"end_line":5,"end_column":0},"operation":"Union","insert_index":-1},"filename":"hello.k","line":4,"column":4,"end_line":5,"end_column":0}]}},"filename":"hello.k","line":2,"column":8,"end_line":5,"end_column":1},"type_annotation":null,"ty":null}},"filename":"hello.k","line":2,"column":0,"end_line":5,"end_column":1}],"comments":[]} - "#]], - ); - - check_parsing_file_ast_json( - "hello.k", - r####" -# comment1 -a = 1 -# comment22 -b = 2 -# comment333 -c = 3 # comment4444 - "####, - expect![[r###" - {"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":5},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":5,"column":4,"end_line":5,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":5},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"c","filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":7,"column":4,"end_line":7,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":5}],"comments":[{"node":{"text":"# comment1"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":10},{"node":{"text":"# comment22"},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":11},{"node":{"text":"# comment333"},"filename":"hello.k","line":6,"column":0,"end_line":6,"end_column":12},{"node":{"text":"# comment4444"},"filename":"hello.k","line":7,"column":6,"end_line":7,"end_column":19}]} - "###]], - ); -} - #[test] fn test_parse_file() { let filenames = vec![ diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index 62f53a698..d4363a73b 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -10,6 +10,7 @@ use crate::*; use core::any::Any; +mod ast; mod error_recovery; mod expr; mod types; @@ -54,6 +55,16 @@ macro_rules! parse_type_node_snapshot { }; } +#[macro_export] +macro_rules! parse_file_ast_json_snapshot { + ($name:ident, $filename:expr, $src:expr) => { + #[test] + fn $name() { + insta::assert_snapshot!($crate::tests::parsing_file_ast_json($filename, $src)); + } + }; +} + pub(crate) fn parsing_expr_string(src: &str) -> String { let sm = SourceMap::new(FilePathMapping::empty()); let sf = sm.new_source_file(PathBuf::from("").into(), src.to_string()); @@ -112,6 +123,16 @@ pub(crate) fn parsing_type_node_string(src: &str) -> String { }) } +pub(crate) fn parsing_file_ast_json(filename: &str, src: &str) -> String { + let m = crate::parse_file_with_global_session( + Arc::new(ParseSession::default()), + filename, + Some(src.into()), + ) + .unwrap(); + serde_json::ser::to_string(&m).unwrap() +} + pub fn check_result_panic_info(result: Result<(), Box>) { if let Err(e) = result { assert!(e.downcast::().is_ok()); diff --git a/kclvm/parser/src/tests/ast.rs b/kclvm/parser/src/tests/ast.rs new file mode 100644 index 000000000..337c6b4bd --- /dev/null +++ b/kclvm/parser/src/tests/ast.rs @@ -0,0 +1,70 @@ +use crate::tests::parse_file_ast_json_snapshot; + +parse_file_ast_json_snapshot!( + schema_stmt, + "hello.k", + r####" +schema TestBool: + [] + [str ]: int + [a: str]: int + [a: ...str]: int + [...str]: int + a: int + b?: str + c: int = 0 + d?: str = "" + + [a] + [a, b, c] + [ + 1 + ] + [ + a + ] + [a for a in [1, 2, 3]] + [ + a for a in [1, 2, 3] + ] + + check: + a > 1, "msg" + name not None, "we fail here" + "#### +); +parse_file_ast_json_snapshot!(assign_stmt, "hello.k", r####"a=123"####); +parse_file_ast_json_snapshot!( + if_stmt_0, + "hello.k", + r####" +a = 10 +b = 12 +_condition = 0 +if a == 11 or b == 13: _condition = 1 +elif a == 10 and b == 12: _condition = 2 +condition = _condition + "#### +); +parse_file_ast_json_snapshot!( + if_stmt_1, + "hello.k", + r####" +data2 = { + **{key = "value1"} + if a == 123: if b == 456: key = "value2" +} + "#### +); +parse_file_ast_json_snapshot!( + basic_stmt, + "hello.k", + r####" +# comment1 +a = 1 +# comment22 +b = 2 +# comment333 +c = 3 # comment4444 + "#### +); diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap new file mode 100644 index 000000000..167cd43a8 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__assign_stmt.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/ast.rs +expression: "crate::tests::parsing_file_ast_json(\"hello.k\", r####\"a=123\"####)" +--- +{"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":123}}},"filename":"hello.k","line":1,"column":2,"end_line":1,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":1,"column":0,"end_line":1,"end_column":5}],"comments":[]} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap new file mode 100644 index 000000000..1cc4ff3bb --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__basic_stmt.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/ast.rs +expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\n# comment1\na = 1\n# comment22\nb = 2\n# comment333\nc = 3 # comment4444\n \"####)" +--- +{"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":5},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":5,"column":4,"end_line":5,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":5,"column":0,"end_line":5,"end_column":5},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"c","filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":7,"column":4,"end_line":7,"end_column":5},"type_annotation":null,"ty":null}},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":5}],"comments":[{"node":{"text":"# comment1"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":10},{"node":{"text":"# comment22"},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":11},{"node":{"text":"# comment333"},"filename":"hello.k","line":6,"column":0,"end_line":6,"end_column":12},{"node":{"text":"# comment4444"},"filename":"hello.k","line":7,"column":6,"end_line":7,"end_column":19}]} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap new file mode 100644 index 000000000..2b85b4fcf --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_0.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/ast.rs +expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\na = 10\nb = 12\n_condition = 0\nif a == 11 or b == 13: _condition = 1\nelif a == 10 and b == 12: _condition = 2\ncondition = _condition\n \"####)" +--- +{"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"hello.k","line":2,"column":4,"end_line":2,"end_column":6},"type_annotation":null,"ty":null}},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":6},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":12}}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6},"type_annotation":null,"ty":null}},"filename":"hello.k","line":3,"column":0,"end_line":3,"end_column":6},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":10}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":10}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":0}}},"filename":"hello.k","line":4,"column":13,"end_line":4,"end_column":14},"type_annotation":null,"ty":null}},"filename":"hello.k","line":4,"column":0,"end_line":4,"end_column":14},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":33}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":33}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":5,"column":36,"end_line":5,"end_column":37},"type_annotation":null,"ty":null}},"filename":"hello.k","line":5,"column":23,"end_line":5,"end_column":37}],"cond":{"node":{"Binary":{"left":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":4},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":11}}},"filename":"hello.k","line":5,"column":8,"end_line":5,"end_column":10}]}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":21},"op":{"Bin":"Or"},"right":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":15}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":15},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":13}}},"filename":"hello.k","line":5,"column":19,"end_line":5,"end_column":21}]}},"filename":"hello.k","line":5,"column":14,"end_line":5,"end_column":21}}},"filename":"hello.k","line":5,"column":3,"end_line":5,"end_column":21},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_condition","filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":36}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":36}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":6,"column":39,"end_line":6,"end_column":40},"type_annotation":null,"ty":null}},"filename":"hello.k","line":6,"column":26,"end_line":6,"end_column":40}],"cond":{"node":{"Binary":{"left":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":6},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"hello.k","line":6,"column":10,"end_line":6,"end_column":12}]}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":24},"op":{"Bin":"And"},"right":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":18}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":18},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":12}}},"filename":"hello.k","line":6,"column":22,"end_line":6,"end_column":24}]}},"filename":"hello.k","line":6,"column":17,"end_line":6,"end_column":24}}},"filename":"hello.k","line":6,"column":5,"end_line":6,"end_column":24},"orelse":[]}},"filename":"hello.k","line":6,"column":0,"end_line":7,"end_column":0}]}},"filename":"hello.k","line":5,"column":0,"end_line":7,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"condition","filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":9}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":9}],"value":{"node":{"Identifier":{"names":[{"node":"_condition","filename":"hello.k","line":7,"column":12,"end_line":7,"end_column":22}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":7,"column":12,"end_line":7,"end_column":22},"type_annotation":null,"ty":null}},"filename":"hello.k","line":7,"column":0,"end_line":7,"end_column":22}],"comments":[]} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap new file mode 100644 index 000000000..12570c4bf --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__if_stmt_1.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/ast.rs +expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\ndata2 = {\n **{key = \"value1\"}\n if a == 123: if b == 456: key = \"value2\"\n}\n \"####)" +--- +{"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"data2","filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":5}],"pkgpath":"","ctx":"Store"},"filename":"hello.k","line":2,"column":0,"end_line":2,"end_column":5}],"value":{"node":{"Config":{"items":[{"node":{"key":null,"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"key","filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":10}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":10},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"value1\"","value":"value1"}},"filename":"hello.k","line":3,"column":13,"end_line":3,"end_column":21},"operation":"Override","insert_index":-1},"filename":"hello.k","line":3,"column":7,"end_line":3,"end_column":21}]}},"filename":"hello.k","line":3,"column":6,"end_line":3,"end_column":22},"operation":"Union","insert_index":-1},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":22},{"node":{"key":null,"value":{"node":{"ConfigIfEntry":{"if_cond":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":123}}},"filename":"hello.k","line":4,"column":12,"end_line":4,"end_column":15}]}},"filename":"hello.k","line":4,"column":7,"end_line":4,"end_column":15},"items":[{"node":{"key":null,"value":{"node":{"ConfigIfEntry":{"if_cond":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":21}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":21},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":456}}},"filename":"hello.k","line":4,"column":25,"end_line":4,"end_column":28}]}},"filename":"hello.k","line":4,"column":20,"end_line":4,"end_column":28},"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"key","filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"value2\"","value":"value2"}},"filename":"hello.k","line":4,"column":36,"end_line":4,"end_column":44},"operation":"Override","insert_index":-1},"filename":"hello.k","line":4,"column":30,"end_line":4,"end_column":44}],"orelse":null}},"filename":"hello.k","line":4,"column":17,"end_line":5,"end_column":0},"operation":"Override","insert_index":-1},"filename":"hello.k","line":4,"column":17,"end_line":5,"end_column":0}],"orelse":null}},"filename":"hello.k","line":4,"column":4,"end_line":5,"end_column":0},"operation":"Union","insert_index":-1},"filename":"hello.k","line":4,"column":4,"end_line":5,"end_column":0}]}},"filename":"hello.k","line":2,"column":8,"end_line":5,"end_column":1},"type_annotation":null,"ty":null}},"filename":"hello.k","line":2,"column":0,"end_line":5,"end_column":1}],"comments":[]} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap new file mode 100644 index 000000000..4ca3b627b --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__ast__schema_stmt.snap @@ -0,0 +1,5 @@ +--- +source: parser/src/tests/ast.rs +expression: "crate::tests::parsing_file_ast_json(\"hello.k\",\n r####\"\nschema TestBool:\n []\n [str ]: int\n [a: str]: int\n [a: ...str]: int\n [...str]: int\n a: int\n b?: str\n c: int = 0\n d?: str = \"\"\n\n [a]\n [a, b, c]\n [\n 1\n ]\n [\n a\n ]\n [a for a in [1, 2, 3]]\n [\n a for a in [1, 2, 3]\n ]\n\n check:\n a > 1, \"msg\"\n name not None, \"we fail here\"\n \"####)" +--- +{"filename":"hello.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"TestBool","filename":"hello.k","line":2,"column":7,"end_line":2,"end_column":15},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[],"ctx":"Load"}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6}]}},"filename":"hello.k","line":3,"column":4,"end_line":3,"end_column":6},{"node":{"SchemaAttr":{"doc":"","name":{"node":"a","filename":"hello.k","line":8,"column":4,"end_line":8,"end_column":5},"type_str":{"node":"int","filename":"hello.k","line":8,"column":7,"end_line":8,"end_column":10},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":8,"column":7,"end_line":8,"end_column":10}}},"filename":"hello.k","line":8,"column":4,"end_line":8,"end_column":10},{"node":{"SchemaAttr":{"doc":"","name":{"node":"b","filename":"hello.k","line":9,"column":4,"end_line":9,"end_column":5},"type_str":{"node":"str","filename":"hello.k","line":9,"column":8,"end_line":9,"end_column":11},"op":null,"value":null,"is_optional":true,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":9,"column":8,"end_line":9,"end_column":11}}},"filename":"hello.k","line":9,"column":4,"end_line":10,"end_column":0},{"node":{"SchemaAttr":{"doc":"","name":{"node":"c","filename":"hello.k","line":10,"column":4,"end_line":10,"end_column":5},"type_str":{"node":"int","filename":"hello.k","line":10,"column":7,"end_line":10,"end_column":10},"op":{"Aug":"Assign"},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":0}}},"filename":"hello.k","line":10,"column":13,"end_line":10,"end_column":14},"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":10,"column":7,"end_line":10,"end_column":10}}},"filename":"hello.k","line":10,"column":4,"end_line":10,"end_column":14},{"node":{"SchemaAttr":{"doc":"","name":{"node":"d","filename":"hello.k","line":11,"column":4,"end_line":11,"end_column":5},"type_str":{"node":"str","filename":"hello.k","line":11,"column":8,"end_line":11,"end_column":11},"op":{"Aug":"Assign"},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"\"","value":""}},"filename":"hello.k","line":11,"column":14,"end_line":11,"end_column":16},"is_optional":true,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello.k","line":11,"column":8,"end_line":11,"end_column":11}}},"filename":"hello.k","line":11,"column":4,"end_line":13,"end_column":0},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":13,"column":5,"end_line":13,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":13,"column":5,"end_line":13,"end_column":6}],"ctx":"Load"}},"filename":"hello.k","line":13,"column":4,"end_line":13,"end_column":7}]}},"filename":"hello.k","line":13,"column":4,"end_line":13,"end_column":7},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":14,"column":5,"end_line":14,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":5,"end_line":14,"end_column":6},{"node":{"Identifier":{"names":[{"node":"b","filename":"hello.k","line":14,"column":8,"end_line":14,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":8,"end_line":14,"end_column":9},{"node":{"Identifier":{"names":[{"node":"c","filename":"hello.k","line":14,"column":11,"end_line":14,"end_column":12}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":14,"column":11,"end_line":14,"end_column":12}],"ctx":"Load"}},"filename":"hello.k","line":14,"column":4,"end_line":14,"end_column":13}]}},"filename":"hello.k","line":14,"column":4,"end_line":14,"end_column":13},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":16,"column":8,"end_line":16,"end_column":9}],"ctx":"Load"}},"filename":"hello.k","line":15,"column":4,"end_line":17,"end_column":5}]}},"filename":"hello.k","line":15,"column":4,"end_line":17,"end_column":5},{"node":{"Expr":{"exprs":[{"node":{"List":{"elts":[{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":19,"column":8,"end_line":19,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":19,"column":8,"end_line":19,"end_column":9}],"ctx":"Load"}},"filename":"hello.k","line":18,"column":4,"end_line":20,"end_column":5}]}},"filename":"hello.k","line":18,"column":4,"end_line":20,"end_column":5},{"node":{"Expr":{"exprs":[{"node":{"ListComp":{"elt":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":21,"column":5,"end_line":21,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":21,"column":5,"end_line":21,"end_column":6},"generators":[{"node":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":21,"column":11,"end_line":21,"end_column":12}],"pkgpath":"","ctx":"Load"},"filename":"hello.k","line":21,"column":11,"end_line":21,"end_column":12}],"iter":{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":21,"column":17,"end_line":21,"end_column":18},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":21,"column":20,"end_line":21,"end_column":21},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":21,"column":23,"end_line":21,"end_column":24}],"ctx":"Load"}},"filename":"hello.k","line":21,"column":16,"end_line":21,"end_column":25},"ifs":[]},"filename":"hello.k","line":21,"column":7,"end_line":21,"end_column":25}]}},"filename":"hello.k","line":21,"column":4,"end_line":21,"end_column":26}]}},"filename":"hello.k","line":21,"column":4,"end_line":21,"end_column":26},{"node":{"Expr":{"exprs":[{"node":{"ListComp":{"elt":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":23,"column":8,"end_line":23,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":23,"column":8,"end_line":23,"end_column":9},"generators":[{"node":{"targets":[{"node":{"names":[{"node":"a","filename":"hello.k","line":23,"column":14,"end_line":23,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"hello.k","line":23,"column":14,"end_line":23,"end_column":15}],"iter":{"node":{"List":{"elts":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":23,"column":20,"end_line":23,"end_column":21},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"hello.k","line":23,"column":23,"end_line":23,"end_column":24},{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"hello.k","line":23,"column":26,"end_line":23,"end_column":27}],"ctx":"Load"}},"filename":"hello.k","line":23,"column":19,"end_line":23,"end_column":28},"ifs":[]},"filename":"hello.k","line":23,"column":10,"end_line":24,"end_column":0}]}},"filename":"hello.k","line":22,"column":4,"end_line":24,"end_column":5}]}},"filename":"hello.k","line":22,"column":4,"end_line":24,"end_column":5}],"decorators":[],"checks":[{"node":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":9},"ops":["Gt"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"hello.k","line":27,"column":12,"end_line":27,"end_column":13}]}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":13},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"msg\"","value":"msg"}},"filename":"hello.k","line":27,"column":15,"end_line":27,"end_column":20}},"filename":"hello.k","line":27,"column":8,"end_line":27,"end_column":20},{"node":{"test":{"node":{"Identifier":{"names":[{"node":"name","filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12}],"pkgpath":"","ctx":"Load"}},"filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12},"if_cond":null,"msg":null},"filename":"hello.k","line":28,"column":8,"end_line":28,"end_column":12},{"node":{"test":{"node":{"Unary":{"op":"Not","operand":{"node":{"NameConstantLit":{"value":"None"}},"filename":"hello.k","line":28,"column":17,"end_line":28,"end_column":21}}},"filename":"hello.k","line":28,"column":13,"end_line":28,"end_column":21},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"we fail here\"","value":"we fail here"}},"filename":"hello.k","line":28,"column":23,"end_line":28,"end_column":37}},"filename":"hello.k","line":28,"column":13,"end_line":28,"end_column":37}],"index_signature":{"node":{"key_name":null,"key_type":{"node":"str","filename":"hello.k","line":7,"column":8,"end_line":7,"end_column":11},"value_type":{"node":"int","filename":"hello.k","line":7,"column":14,"end_line":7,"end_column":17},"value":null,"any_other":true,"value_ty":{"node":{"Basic":"Int"},"filename":"hello.k","line":7,"column":14,"end_line":7,"end_column":17}},"filename":"hello.k","line":7,"column":4,"end_line":8,"end_column":0}}},"filename":"hello.k","line":2,"column":0,"end_line":29,"end_column":8}],"comments":[]} From c4928171190044cf9415ca0a86569560b5e8f176 Mon Sep 17 00:00:00 2001 From: jakezhu9 Date: Wed, 18 Oct 2023 16:20:28 +0800 Subject: [PATCH 4/4] test: move parser file unit tests to snaptest Signed-off-by: jakezhu9 --- kclvm/parser/src/parser/tests.rs | 38 ------------------- kclvm/parser/src/tests.rs | 18 +++++++++ kclvm/parser/src/tests/file.rs | 19 ++++++++++ .../kclvm_parser__tests__file__assert_1.snap} | 4 ++ .../kclvm_parser__tests__file__assert_2.snap} | 6 ++- .../kclvm_parser__tests__file__assert_3.snap} | 6 ++- ...lvm_parser__tests__file__assert_if_0.snap} | 6 ++- ...lvm_parser__tests__file__assert_if_1.snap} | 6 ++- ...lvm_parser__tests__file__assert_if_2.snap} | 6 ++- .../kclvm_parser__tests__file__assign_1.snap} | 6 ++- ...m_parser__tests__file__config_expr_1.snap} | 6 ++- ...m_parser__tests__file__config_expr_2.snap} | 6 ++- ...m_parser__tests__file__config_expr_3.snap} | 6 ++- ...m_parser__tests__file__config_expr_4.snap} | 6 ++- ...kclvm_parser__tests__file__hello_win.snap} | 6 ++- .../kclvm_parser__tests__file__if_1.snap} | 6 ++- .../kclvm_parser__tests__file__if_2.snap} | 6 ++- .../kclvm_parser__tests__file__if_3.snap} | 6 ++- .../kclvm_parser__tests__file__import_1.snap} | 4 ++ .../kclvm_parser__tests__file__type_1.snap} | 6 ++- kclvm/parser/testdata/Makefile | 13 ------- 21 files changed, 120 insertions(+), 66 deletions(-) create mode 100644 kclvm/parser/src/tests/file.rs rename kclvm/parser/{testdata/assert-01.k.json => src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap} (89%) rename kclvm/parser/{testdata/assert-02.k.json => src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap} (94%) rename kclvm/parser/{testdata/assert-03.k.json => src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap} (96%) rename kclvm/parser/{testdata/assert-if-0.k.json => src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap} (95%) rename kclvm/parser/{testdata/assert-if-1.k.json => src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap} (94%) rename kclvm/parser/{testdata/assert-if-2.k.json => src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap} (96%) rename kclvm/parser/{testdata/assign-01.k.json => src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap} (95%) rename kclvm/parser/{testdata/config_expr-01.k.json => src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap} (81%) rename kclvm/parser/{testdata/config_expr-02.k.json => src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap} (91%) rename kclvm/parser/{testdata/config_expr-03.k.json => src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap} (97%) rename kclvm/parser/{testdata/config_expr-04.k.json => src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap} (98%) rename kclvm/parser/{testdata/hello_win.k.json => src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap} (91%) rename kclvm/parser/{testdata/if-01.k.json => src/tests/snapshots/kclvm_parser__tests__file__if_1.snap} (90%) rename kclvm/parser/{testdata/if-02.k.json => src/tests/snapshots/kclvm_parser__tests__file__if_2.snap} (97%) rename kclvm/parser/{testdata/if-03.k.json => src/tests/snapshots/kclvm_parser__tests__file__if_3.snap} (84%) rename kclvm/parser/{testdata/import-01.k.json => src/tests/snapshots/kclvm_parser__tests__file__import_1.snap} (87%) rename kclvm/parser/{testdata/type-01.k.json => src/tests/snapshots/kclvm_parser__tests__file__type_1.snap} (97%) delete mode 100644 kclvm/parser/testdata/Makefile diff --git a/kclvm/parser/src/parser/tests.rs b/kclvm/parser/src/parser/tests.rs index 46f2251ef..5c82ed8c0 100644 --- a/kclvm/parser/src/parser/tests.rs +++ b/kclvm/parser/src/parser/tests.rs @@ -1,44 +1,6 @@ use crate::parse_file; use regex::Regex; -fn check_parsing_module(filename: &str, src: &str, expect: &str) { - let m = crate::parse_file(filename, Some(src.to_string())).expect(filename); - let actual = format!("{}\n", serde_json::ser::to_string(&m).unwrap()); - assert_eq!(actual.trim(), expect.trim()); -} - -#[test] -fn test_parse_file() { - let filenames = vec![ - "testdata/assert-01.k", - "testdata/assert-02.k", - "testdata/assert-03.k", - "testdata/assert-if-0.k", - "testdata/assert-if-1.k", - "testdata/assert-if-2.k", - "testdata/assign-01.k", - "testdata/config_expr-01.k", - "testdata/config_expr-02.k", - "testdata/config_expr-03.k", - "testdata/config_expr-04.k", - "testdata/import-01.k", - "testdata/if-01.k", - "testdata/if-02.k", - "testdata/if-03.k", - "testdata/type-01.k", - "testdata/hello_win.k", - ]; - for filename in filenames { - let code = std::fs::read_to_string(filename).unwrap(); - let expect = std::fs::read_to_string(filename.to_string() + ".json").unwrap(); - check_parsing_module( - filename.trim_start_matches("testdata/"), - code.as_str(), - expect.as_str(), - ); - } -} - #[test] fn test_parse_file_not_found() { match parse_file("The file path is invalid", None) { diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index d4363a73b..736a7c851 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -13,6 +13,7 @@ use core::any::Any; mod ast; mod error_recovery; mod expr; +mod file; mod types; #[macro_export] @@ -65,6 +66,16 @@ macro_rules! parse_file_ast_json_snapshot { }; } +#[macro_export] +macro_rules! parse_file_snapshot { + ($name:ident, $filename:expr) => { + #[test] + fn $name() { + insta::assert_snapshot!($crate::tests::parsing_file_string($filename)); + } + }; +} + pub(crate) fn parsing_expr_string(src: &str) -> String { let sm = SourceMap::new(FilePathMapping::empty()); let sf = sm.new_source_file(PathBuf::from("").into(), src.to_string()); @@ -133,6 +144,13 @@ pub(crate) fn parsing_file_ast_json(filename: &str, src: &str) -> String { serde_json::ser::to_string(&m).unwrap() } +pub(crate) fn parsing_file_string(filename: &str) -> String { + let code = std::fs::read_to_string(filename).unwrap(); + let m = + crate::parse_file(filename.trim_start_matches("testdata/"), Some(code)).expect(filename); + serde_json::ser::to_string(&m).unwrap() +} + pub fn check_result_panic_info(result: Result<(), Box>) { if let Err(e) = result { assert!(e.downcast::().is_ok()); diff --git a/kclvm/parser/src/tests/file.rs b/kclvm/parser/src/tests/file.rs new file mode 100644 index 000000000..83baf2e10 --- /dev/null +++ b/kclvm/parser/src/tests/file.rs @@ -0,0 +1,19 @@ +use crate::tests::parse_file_snapshot; + +parse_file_snapshot!(assert_1, "testdata/assert-01.k"); +parse_file_snapshot!(assert_2, "testdata/assert-02.k"); +parse_file_snapshot!(assert_3, "testdata/assert-03.k"); +parse_file_snapshot!(assert_if_0, "testdata/assert-if-0.k"); +parse_file_snapshot!(assert_if_1, "testdata/assert-if-1.k"); +parse_file_snapshot!(assert_if_2, "testdata/assert-if-2.k"); +parse_file_snapshot!(assign_1, "testdata/assign-01.k"); +parse_file_snapshot!(config_expr_1, "testdata/config_expr-01.k"); +parse_file_snapshot!(config_expr_2, "testdata/config_expr-02.k"); +parse_file_snapshot!(config_expr_3, "testdata/config_expr-03.k"); +parse_file_snapshot!(config_expr_4, "testdata/config_expr-04.k"); +parse_file_snapshot!(import_1, "testdata/import-01.k"); +parse_file_snapshot!(if_1, "testdata/if-01.k"); +parse_file_snapshot!(if_2, "testdata/if-02.k"); +parse_file_snapshot!(if_3, "testdata/if-03.k"); +parse_file_snapshot!(type_1, "testdata/type-01.k"); +parse_file_snapshot!(hello_win, "testdata/hello_win.k"); diff --git a/kclvm/parser/testdata/assert-01.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap similarity index 89% rename from kclvm/parser/testdata/assert-01.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap index 75b5a5f19..a180644c2 100644 --- a/kclvm/parser/testdata/assert-01.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_1.snap @@ -1 +1,5 @@ +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assert-01.k\")" +--- {"filename":"assert-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-01.k","line":1,"column":7,"end_line":1,"end_column":8},"if_cond":null,"msg":null}},"filename":"assert-01.k","line":1,"column":0,"end_line":1,"end_column":8},{"node":{"Assert":{"test":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assert-01.k","line":2,"column":7,"end_line":2,"end_column":8},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"msg\"","value":"msg"}},"filename":"assert-01.k","line":2,"column":10,"end_line":2,"end_column":15}}},"filename":"assert-01.k","line":2,"column":0,"end_line":2,"end_column":15},{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-01.k","line":3,"column":7,"end_line":3,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-01.k","line":3,"column":0,"end_line":3,"end_column":11}],"comments":[]} diff --git a/kclvm/parser/testdata/assert-02.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap similarity index 94% rename from kclvm/parser/testdata/assert-02.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap index bda706403..2e2ec9cbe 100644 --- a/kclvm/parser/testdata/assert-02.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_2.snap @@ -1 +1,5 @@ -{"filename":"assert-02.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-02.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":1,"column":0,"end_line":1,"end_column":11},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-02.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-02.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-02.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":2,"column":0,"end_line":2,"end_column":13},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-02.k","line":3,"column":5,"end_line":3,"end_column":16},"type_annotation":null,"ty":null}},"filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-02.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":4,"column":0,"end_line":4,"end_column":24}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assert-02.k\")" +--- +{"filename":"assert-02.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-02.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":1,"column":0,"end_line":1,"end_column":11},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-02.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-02.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-02.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":2,"column":0,"end_line":2,"end_column":13},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-02.k","line":3,"column":5,"end_line":3,"end_column":16},"type_annotation":null,"ty":null}},"filename":"assert-02.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-02.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-02.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":null,"msg":null}},"filename":"assert-02.k","line":4,"column":0,"end_line":4,"end_column":24}],"comments":[]} diff --git a/kclvm/parser/testdata/assert-03.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap similarity index 96% rename from kclvm/parser/testdata/assert-03.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap index 2b0813456..ffbaa378b 100644 --- a/kclvm/parser/testdata/assert-03.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_3.snap @@ -1 +1,5 @@ -{"filename":"assert-03.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"If":{"body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-03.k","line":2,"column":11,"end_line":2,"end_column":15},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"Error messgae\"","value":"Error messgae"}},"filename":"assert-03.k","line":2,"column":17,"end_line":2,"end_column":32}}},"filename":"assert-03.k","line":2,"column":4,"end_line":2,"end_column":32},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-03.k","line":3,"column":11,"end_line":3,"end_column":12},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-03.k","line":3,"column":16,"end_line":3,"end_column":17}]}},"filename":"assert-03.k","line":3,"column":11,"end_line":3,"end_column":17},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"\"","value":""}},"filename":"assert-03.k","line":3,"column":19,"end_line":3,"end_column":21}}},"filename":"assert-03.k","line":3,"column":4,"end_line":3,"end_column":21},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":6}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-03.k","line":4,"column":9,"end_line":4,"end_column":20},"type_annotation":null,"ty":null}},"filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":13},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-03.k","line":5,"column":17,"end_line":5,"end_column":28}]}},"filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":28},"if_cond":null,"msg":null}},"filename":"assert-03.k","line":5,"column":4,"end_line":5,"end_column":28}],"cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-03.k","line":1,"column":3,"end_line":1,"end_column":7},"orelse":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-03.k","line":7,"column":11,"end_line":7,"end_column":16},"if_cond":null,"msg":null}},"filename":"assert-03.k","line":7,"column":4,"end_line":7,"end_column":16}]}},"filename":"assert-03.k","line":1,"column":0,"end_line":8,"end_column":1}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assert-03.k\")" +--- +{"filename":"assert-03.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"If":{"body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-03.k","line":2,"column":11,"end_line":2,"end_column":15},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"Error messgae\"","value":"Error messgae"}},"filename":"assert-03.k","line":2,"column":17,"end_line":2,"end_column":32}}},"filename":"assert-03.k","line":2,"column":4,"end_line":2,"end_column":32},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-03.k","line":3,"column":11,"end_line":3,"end_column":12},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-03.k","line":3,"column":16,"end_line":3,"end_column":17}]}},"filename":"assert-03.k","line":3,"column":11,"end_line":3,"end_column":17},"if_cond":null,"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"\"","value":""}},"filename":"assert-03.k","line":3,"column":19,"end_line":3,"end_column":21}}},"filename":"assert-03.k","line":3,"column":4,"end_line":3,"end_column":21},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":6}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-03.k","line":4,"column":9,"end_line":4,"end_column":20},"type_annotation":null,"ty":null}},"filename":"assert-03.k","line":4,"column":4,"end_line":4,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":13},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-03.k","line":5,"column":17,"end_line":5,"end_column":28}]}},"filename":"assert-03.k","line":5,"column":11,"end_line":5,"end_column":28},"if_cond":null,"msg":null}},"filename":"assert-03.k","line":5,"column":4,"end_line":5,"end_column":28}],"cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-03.k","line":1,"column":3,"end_line":1,"end_column":7},"orelse":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-03.k","line":7,"column":11,"end_line":7,"end_column":16},"if_cond":null,"msg":null}},"filename":"assert-03.k","line":7,"column":4,"end_line":7,"end_column":16}]}},"filename":"assert-03.k","line":1,"column":0,"end_line":8,"end_column":1}],"comments":[]} diff --git a/kclvm/parser/testdata/assert-if-0.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap similarity index 95% rename from kclvm/parser/testdata/assert-if-0.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap index 30ab48aa0..666c05711 100644 --- a/kclvm/parser/testdata/assert-if-0.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_0.snap @@ -1 +1,5 @@ -{"filename":"assert-if-0.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-0.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-if-0.k","line":1,"column":0,"end_line":1,"end_column":11},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-0.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-0.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-if-0.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-0.k","line":2,"column":17,"end_line":2,"end_column":21},"msg":null}},"filename":"assert-if-0.k","line":2,"column":0,"end_line":2,"end_column":21},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-0.k","line":3,"column":5,"end_line":3,"end_column":16},"type_annotation":null,"ty":null}},"filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-0.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-0.k","line":4,"column":28,"end_line":4,"end_column":30}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-0.k","line":4,"column":28,"end_line":4,"end_column":30},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-0.k","line":4,"column":32,"end_line":4,"end_column":59}}},"filename":"assert-if-0.k","line":4,"column":0,"end_line":4,"end_column":59}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assert-if-0.k\")" +--- +{"filename":"assert-if-0.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-0.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":null,"msg":null}},"filename":"assert-if-0.k","line":1,"column":0,"end_line":1,"end_column":11},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-0.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-0.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-if-0.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-0.k","line":2,"column":17,"end_line":2,"end_column":21},"msg":null}},"filename":"assert-if-0.k","line":2,"column":0,"end_line":2,"end_column":21},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-0.k","line":3,"column":5,"end_line":3,"end_column":16},"type_annotation":null,"ty":null}},"filename":"assert-if-0.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-0.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-if-0.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-0.k","line":4,"column":28,"end_line":4,"end_column":30}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-0.k","line":4,"column":28,"end_line":4,"end_column":30},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-0.k","line":4,"column":32,"end_line":4,"end_column":59}}},"filename":"assert-if-0.k","line":4,"column":0,"end_line":4,"end_column":59}],"comments":[]} diff --git a/kclvm/parser/testdata/assert-if-1.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap similarity index 94% rename from kclvm/parser/testdata/assert-if-1.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap index bed7e15dd..10838ee1c 100644 --- a/kclvm/parser/testdata/assert-if-1.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_1.snap @@ -1 +1,5 @@ -{"filename":"assert-if-1.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-1.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-1.k","line":1,"column":15,"end_line":1,"end_column":20},"msg":null}},"filename":"assert-if-1.k","line":1,"column":0,"end_line":1,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-1.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-1.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-if-1.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-1.k","line":2,"column":17,"end_line":2,"end_column":22},"msg":null}},"filename":"assert-if-1.k","line":2,"column":0,"end_line":2,"end_column":22},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-1.k","line":3,"column":5,"end_line":3,"end_column":16},"type_annotation":null,"ty":null}},"filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-1.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":{"node":{"Unary":{"op":"Not","operand":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-1.k","line":4,"column":32,"end_line":4,"end_column":34}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-1.k","line":4,"column":32,"end_line":4,"end_column":34}}},"filename":"assert-if-1.k","line":4,"column":28,"end_line":4,"end_column":34},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-1.k","line":4,"column":36,"end_line":4,"end_column":63}}},"filename":"assert-if-1.k","line":4,"column":0,"end_line":4,"end_column":63}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assert-if-1.k\")" +--- +{"filename":"assert-if-1.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-1.k","line":1,"column":7,"end_line":1,"end_column":11},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-1.k","line":1,"column":15,"end_line":1,"end_column":20},"msg":null}},"filename":"assert-if-1.k","line":1,"column":0,"end_line":1,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-1.k","line":2,"column":7,"end_line":2,"end_column":8},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-1.k","line":2,"column":12,"end_line":2,"end_column":13}]}},"filename":"assert-if-1.k","line":2,"column":7,"end_line":2,"end_column":13},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-1.k","line":2,"column":17,"end_line":2,"end_column":22},"msg":null}},"filename":"assert-if-1.k","line":2,"column":0,"end_line":2,"end_column":22},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":2}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-1.k","line":3,"column":5,"end_line":3,"end_column":16},"type_annotation":null,"ty":null}},"filename":"assert-if-1.k","line":3,"column":0,"end_line":3,"end_column":16},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":9}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":9},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-1.k","line":4,"column":13,"end_line":4,"end_column":24}]}},"filename":"assert-if-1.k","line":4,"column":7,"end_line":4,"end_column":24},"if_cond":{"node":{"Unary":{"op":"Not","operand":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-1.k","line":4,"column":32,"end_line":4,"end_column":34}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-1.k","line":4,"column":32,"end_line":4,"end_column":34}}},"filename":"assert-if-1.k","line":4,"column":28,"end_line":4,"end_column":34},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-1.k","line":4,"column":36,"end_line":4,"end_column":63}}},"filename":"assert-if-1.k","line":4,"column":0,"end_line":4,"end_column":63}],"comments":[]} diff --git a/kclvm/parser/testdata/assert-if-2.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap similarity index 96% rename from kclvm/parser/testdata/assert-if-2.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap index 9882da148..8edb82dd1 100644 --- a/kclvm/parser/testdata/assert-if-2.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assert_if_2.snap @@ -1 +1,5 @@ -{"filename":"assert-if-2.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"Data","filename":"assert-if-2.k","line":1,"column":7,"end_line":1,"end_column":11},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-2.k","line":2,"column":11,"end_line":2,"end_column":15},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-2.k","line":2,"column":19,"end_line":2,"end_column":24},"msg":null}},"filename":"assert-if-2.k","line":2,"column":4,"end_line":2,"end_column":24},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-2.k","line":3,"column":11,"end_line":3,"end_column":12},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-2.k","line":3,"column":16,"end_line":3,"end_column":17}]}},"filename":"assert-if-2.k","line":3,"column":11,"end_line":3,"end_column":17},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-2.k","line":3,"column":21,"end_line":3,"end_column":26},"msg":null}},"filename":"assert-if-2.k","line":3,"column":4,"end_line":3,"end_column":26},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":6}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-2.k","line":4,"column":9,"end_line":4,"end_column":20},"type_annotation":null,"ty":null}},"filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":13},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-2.k","line":5,"column":17,"end_line":5,"end_column":28}]}},"filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":28},"if_cond":{"node":{"Unary":{"op":"Not","operand":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-2.k","line":5,"column":36,"end_line":5,"end_column":38}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-2.k","line":5,"column":36,"end_line":5,"end_column":38}}},"filename":"assert-if-2.k","line":5,"column":32,"end_line":5,"end_column":38},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-2.k","line":5,"column":40,"end_line":5,"end_column":67}}},"filename":"assert-if-2.k","line":5,"column":4,"end_line":5,"end_column":67}],"decorators":[],"checks":[],"index_signature":null}},"filename":"assert-if-2.k","line":1,"column":0,"end_line":7,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"data","filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":4}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":4}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Data","filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":11}],"pkgpath":"","ctx":"Load"},"filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":11},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[]}},"filename":"assert-if-2.k","line":7,"column":12,"end_line":7,"end_column":14}}},"filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":14},"type_annotation":null,"ty":null}},"filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":14}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assert-if-2.k\")" +--- +{"filename":"assert-if-2.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"Data","filename":"assert-if-2.k","line":1,"column":7,"end_line":1,"end_column":11},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"Assert":{"test":{"node":{"NameConstantLit":{"value":"True"}},"filename":"assert-if-2.k","line":2,"column":11,"end_line":2,"end_column":15},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-2.k","line":2,"column":19,"end_line":2,"end_column":24},"msg":null}},"filename":"assert-if-2.k","line":2,"column":4,"end_line":2,"end_column":24},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-2.k","line":3,"column":11,"end_line":3,"end_column":12},"ops":["Eq"],"comparators":[{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assert-if-2.k","line":3,"column":16,"end_line":3,"end_column":17}]}},"filename":"assert-if-2.k","line":3,"column":11,"end_line":3,"end_column":17},"if_cond":{"node":{"NameConstantLit":{"value":"False"}},"filename":"assert-if-2.k","line":3,"column":21,"end_line":3,"end_column":26},"msg":null}},"filename":"assert-if-2.k","line":3,"column":4,"end_line":3,"end_column":26},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_x","filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":6}],"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-2.k","line":4,"column":9,"end_line":4,"end_column":20},"type_annotation":null,"ty":null}},"filename":"assert-if-2.k","line":4,"column":4,"end_line":4,"end_column":20},{"node":{"Assert":{"test":{"node":{"Compare":{"left":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":13},"ops":["Eq"],"comparators":[{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"good case\"","value":"good case"}},"filename":"assert-if-2.k","line":5,"column":17,"end_line":5,"end_column":28}]}},"filename":"assert-if-2.k","line":5,"column":11,"end_line":5,"end_column":28},"if_cond":{"node":{"Unary":{"op":"Not","operand":{"node":{"Identifier":{"names":[{"node":"_x","filename":"assert-if-2.k","line":5,"column":36,"end_line":5,"end_column":38}],"pkgpath":"","ctx":"Load"}},"filename":"assert-if-2.k","line":5,"column":36,"end_line":5,"end_column":38}}},"filename":"assert-if-2.k","line":5,"column":32,"end_line":5,"end_column":38},"msg":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"_x need to be 'good case'\"","value":"_x need to be 'good case'"}},"filename":"assert-if-2.k","line":5,"column":40,"end_line":5,"end_column":67}}},"filename":"assert-if-2.k","line":5,"column":4,"end_line":5,"end_column":67}],"decorators":[],"checks":[],"index_signature":null}},"filename":"assert-if-2.k","line":1,"column":0,"end_line":7,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"data","filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":4}],"pkgpath":"","ctx":"Store"},"filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":4}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Data","filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":11}],"pkgpath":"","ctx":"Load"},"filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":11},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[]}},"filename":"assert-if-2.k","line":7,"column":12,"end_line":7,"end_column":14}}},"filename":"assert-if-2.k","line":7,"column":7,"end_line":7,"end_column":14},"type_annotation":null,"ty":null}},"filename":"assert-if-2.k","line":7,"column":0,"end_line":7,"end_column":14}],"comments":[]} diff --git a/kclvm/parser/testdata/assign-01.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap similarity index 95% rename from kclvm/parser/testdata/assign-01.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap index 8f6def8f8..46ab2e77f 100644 --- a/kclvm/parser/testdata/assign-01.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__assign_1.snap @@ -1 +1,5 @@ -{"filename":"assign-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assign-01.k","line":1,"column":2,"end_line":1,"end_column":3},"type_annotation":null,"ty":null}},"filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":3},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":1}],"value":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assign-01.k","line":2,"column":4,"end_line":2,"end_column":5},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":2,"column":8,"end_line":2,"end_column":9}}},"filename":"assign-01.k","line":2,"column":4,"end_line":2,"end_column":9},"type_annotation":null,"ty":null}},"filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":9},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"c","filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":3,"column":4,"end_line":3,"end_column":5},"op":{"Bin":"Add"},"right":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":3,"column":8,"end_line":3,"end_column":9},"op":{"Bin":"Mul"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"assign-01.k","line":3,"column":10,"end_line":3,"end_column":11}}},"filename":"assign-01.k","line":3,"column":8,"end_line":3,"end_column":11}}},"filename":"assign-01.k","line":3,"column":4,"end_line":3,"end_column":11},"type_annotation":null,"ty":null}},"filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":11}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/assign-01.k\")" +--- +{"filename":"assign-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assign-01.k","line":1,"column":2,"end_line":1,"end_column":3},"type_annotation":null,"ty":null}},"filename":"assign-01.k","line":1,"column":0,"end_line":1,"end_column":3},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"b","filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":1}],"value":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"assign-01.k","line":2,"column":4,"end_line":2,"end_column":5},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":2,"column":8,"end_line":2,"end_column":9}}},"filename":"assign-01.k","line":2,"column":4,"end_line":2,"end_column":9},"type_annotation":null,"ty":null}},"filename":"assign-01.k","line":2,"column":0,"end_line":2,"end_column":9},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"c","filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":1}],"value":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":3,"column":4,"end_line":3,"end_column":5},"op":{"Bin":"Add"},"right":{"node":{"Binary":{"left":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"assign-01.k","line":3,"column":8,"end_line":3,"end_column":9},"op":{"Bin":"Mul"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"assign-01.k","line":3,"column":10,"end_line":3,"end_column":11}}},"filename":"assign-01.k","line":3,"column":8,"end_line":3,"end_column":11}}},"filename":"assign-01.k","line":3,"column":4,"end_line":3,"end_column":11},"type_annotation":null,"ty":null}},"filename":"assign-01.k","line":3,"column":0,"end_line":3,"end_column":11}],"comments":[]} diff --git a/kclvm/parser/testdata/config_expr-01.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap similarity index 81% rename from kclvm/parser/testdata/config_expr-01.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap index 2cf0a652e..e479f2207 100644 --- a/kclvm/parser/testdata/config_expr-01.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_1.snap @@ -1 +1,5 @@ -{"filename":"config_expr-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-01.k","line":1,"column":0,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-01.k","line":1,"column":0,"end_line":1,"end_column":6}],"value":{"node":{"Config":{"items":[]}},"filename":"config_expr-01.k","line":1,"column":9,"end_line":2,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-01.k","line":1,"column":0,"end_line":2,"end_column":1}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/config_expr-01.k\")" +--- +{"filename":"config_expr-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-01.k","line":1,"column":0,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-01.k","line":1,"column":0,"end_line":1,"end_column":6}],"value":{"node":{"Config":{"items":[]}},"filename":"config_expr-01.k","line":1,"column":9,"end_line":2,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-01.k","line":1,"column":0,"end_line":2,"end_column":1}],"comments":[]} diff --git a/kclvm/parser/testdata/config_expr-02.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap similarity index 91% rename from kclvm/parser/testdata/config_expr-02.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap index a279c7914..7a39cd87a 100644 --- a/kclvm/parser/testdata/config_expr-02.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_2.snap @@ -1 +1,5 @@ -{"filename":"config_expr-02.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-02.k","line":1,"column":0,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-02.k","line":1,"column":0,"end_line":1,"end_column":6}],"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"k1","filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":6},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":111}}},"filename":"config_expr-02.k","line":2,"column":9,"end_line":2,"end_column":12},"operation":"Override","insert_index":-1},"filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":12},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"k2","filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":6},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":222}}},"filename":"config_expr-02.k","line":3,"column":9,"end_line":3,"end_column":12},"operation":"Override","insert_index":-1},"filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":12}]}},"filename":"config_expr-02.k","line":1,"column":9,"end_line":4,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-02.k","line":1,"column":0,"end_line":4,"end_column":1}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/config_expr-02.k\")" +--- +{"filename":"config_expr-02.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-02.k","line":1,"column":0,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-02.k","line":1,"column":0,"end_line":1,"end_column":6}],"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"k1","filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":6},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":111}}},"filename":"config_expr-02.k","line":2,"column":9,"end_line":2,"end_column":12},"operation":"Override","insert_index":-1},"filename":"config_expr-02.k","line":2,"column":4,"end_line":2,"end_column":12},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"k2","filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":6},"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":222}}},"filename":"config_expr-02.k","line":3,"column":9,"end_line":3,"end_column":12},"operation":"Override","insert_index":-1},"filename":"config_expr-02.k","line":3,"column":4,"end_line":3,"end_column":12}]}},"filename":"config_expr-02.k","line":1,"column":9,"end_line":4,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-02.k","line":1,"column":0,"end_line":4,"end_column":1}],"comments":[]} diff --git a/kclvm/parser/testdata/config_expr-03.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap similarity index 97% rename from kclvm/parser/testdata/config_expr-03.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap index ea175b7ad..51377ba50 100644 --- a/kclvm/parser/testdata/config_expr-03.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_3.snap @@ -1 +1,5 @@ -{"filename":"config_expr-03.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-03.k","line":3,"column":0,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-03.k","line":3,"column":0,"end_line":3,"end_column":6}],"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-03.k","line":4,"column":4,"end_line":4,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":4,"column":4,"end_line":4,"end_column":8},"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-03.k","line":5,"column":8,"end_line":5,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":5,"column":8,"end_line":5,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_1\"","value":"ENV_1"}},"filename":"config_expr-03.k","line":6,"column":19,"end_line":6,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"1\"","value":"1"}},"filename":"config_expr-03.k","line":6,"column":35,"end_line":6,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":38}]}},"filename":"config_expr-03.k","line":6,"column":12,"end_line":6,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-03.k","line":5,"column":13,"end_line":7,"end_column":9},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":5,"column":8,"end_line":7,"end_column":9}]}},"filename":"config_expr-03.k","line":4,"column":10,"end_line":8,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":4,"column":4,"end_line":8,"end_column":5},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-03.k","line":9,"column":4,"end_line":9,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":9,"column":4,"end_line":9,"end_column":8},"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-03.k","line":10,"column":8,"end_line":10,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":10,"column":8,"end_line":10,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_2\"","value":"ENV_2"}},"filename":"config_expr-03.k","line":11,"column":19,"end_line":11,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"2\"","value":"2"}},"filename":"config_expr-03.k","line":11,"column":35,"end_line":11,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":38}]}},"filename":"config_expr-03.k","line":11,"column":12,"end_line":11,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-03.k","line":10,"column":15,"end_line":12,"end_column":9},"operation":"Insert","insert_index":-1},"filename":"config_expr-03.k","line":10,"column":8,"end_line":12,"end_column":9}]}},"filename":"config_expr-03.k","line":9,"column":10,"end_line":13,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":9,"column":4,"end_line":13,"end_column":5}]}},"filename":"config_expr-03.k","line":3,"column":9,"end_line":14,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-03.k","line":3,"column":0,"end_line":14,"end_column":1}],"comments":[{"node":{"text":"# test/grammar/attr_operator/config_inside/insert/dict_0/main.k"},"filename":"config_expr-03.k","line":1,"column":0,"end_line":1,"end_column":63}]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/config_expr-03.k\")" +--- +{"filename":"config_expr-03.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-03.k","line":3,"column":0,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-03.k","line":3,"column":0,"end_line":3,"end_column":6}],"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-03.k","line":4,"column":4,"end_line":4,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":4,"column":4,"end_line":4,"end_column":8},"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-03.k","line":5,"column":8,"end_line":5,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":5,"column":8,"end_line":5,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_1\"","value":"ENV_1"}},"filename":"config_expr-03.k","line":6,"column":19,"end_line":6,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":6,"column":13,"end_line":6,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"1\"","value":"1"}},"filename":"config_expr-03.k","line":6,"column":35,"end_line":6,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":6,"column":28,"end_line":6,"end_column":38}]}},"filename":"config_expr-03.k","line":6,"column":12,"end_line":6,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-03.k","line":5,"column":13,"end_line":7,"end_column":9},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":5,"column":8,"end_line":7,"end_column":9}]}},"filename":"config_expr-03.k","line":4,"column":10,"end_line":8,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":4,"column":4,"end_line":8,"end_column":5},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-03.k","line":9,"column":4,"end_line":9,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":9,"column":4,"end_line":9,"end_column":8},"value":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-03.k","line":10,"column":8,"end_line":10,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":10,"column":8,"end_line":10,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_2\"","value":"ENV_2"}},"filename":"config_expr-03.k","line":11,"column":19,"end_line":11,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":11,"column":13,"end_line":11,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"2\"","value":"2"}},"filename":"config_expr-03.k","line":11,"column":35,"end_line":11,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":11,"column":28,"end_line":11,"end_column":38}]}},"filename":"config_expr-03.k","line":11,"column":12,"end_line":11,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-03.k","line":10,"column":15,"end_line":12,"end_column":9},"operation":"Insert","insert_index":-1},"filename":"config_expr-03.k","line":10,"column":8,"end_line":12,"end_column":9}]}},"filename":"config_expr-03.k","line":9,"column":10,"end_line":13,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-03.k","line":9,"column":4,"end_line":13,"end_column":5}]}},"filename":"config_expr-03.k","line":3,"column":9,"end_line":14,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-03.k","line":3,"column":0,"end_line":14,"end_column":1}],"comments":[{"node":{"text":"# test/grammar/attr_operator/config_inside/insert/dict_0/main.k"},"filename":"config_expr-03.k","line":1,"column":0,"end_line":1,"end_column":63}]} diff --git a/kclvm/parser/testdata/config_expr-04.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap similarity index 98% rename from kclvm/parser/testdata/config_expr-04.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap index 9d1547d94..af2fabff1 100644 --- a/kclvm/parser/testdata/config_expr-04.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__config_expr_4.snap @@ -1 +1,5 @@ -{"filename":"config_expr-04.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"Env","filename":"config_expr-04.k","line":3,"column":7,"end_line":3,"end_column":10},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"name","filename":"config_expr-04.k","line":4,"column":4,"end_line":4,"end_column":8},"type_str":{"node":"str","filename":"config_expr-04.k","line":4,"column":10,"end_line":4,"end_column":13},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"config_expr-04.k","line":4,"column":10,"end_line":4,"end_column":13}}},"filename":"config_expr-04.k","line":4,"column":4,"end_line":4,"end_column":13},{"node":{"SchemaAttr":{"doc":"","name":{"node":"value","filename":"config_expr-04.k","line":5,"column":4,"end_line":5,"end_column":9},"type_str":{"node":"str","filename":"config_expr-04.k","line":5,"column":11,"end_line":5,"end_column":14},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"config_expr-04.k","line":5,"column":11,"end_line":5,"end_column":14}}},"filename":"config_expr-04.k","line":5,"column":4,"end_line":5,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":3,"column":0,"end_line":7,"end_column":0},{"node":{"Schema":{"doc":"","name":{"node":"Main","filename":"config_expr-04.k","line":7,"column":7,"end_line":7,"end_column":11},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"env","filename":"config_expr-04.k","line":8,"column":4,"end_line":8,"end_column":7},"type_str":{"node":"[Env]","filename":"config_expr-04.k","line":8,"column":9,"end_line":8,"end_column":14},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"List":{"inner_type":{"node":{"Named":{"names":[{"node":"Env","filename":"config_expr-04.k","line":8,"column":10,"end_line":8,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":8,"column":10,"end_line":8,"end_column":13}}},"filename":"config_expr-04.k","line":8,"column":9,"end_line":8,"end_column":14}}},"filename":"config_expr-04.k","line":8,"column":4,"end_line":8,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":7,"column":0,"end_line":10,"end_column":0},{"node":{"Schema":{"doc":"","name":{"node":"Config","filename":"config_expr-04.k","line":10,"column":7,"end_line":10,"end_column":13},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"main","filename":"config_expr-04.k","line":11,"column":4,"end_line":11,"end_column":8},"type_str":{"node":"Main","filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Named":{"names":[{"node":"Main","filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14}}},"filename":"config_expr-04.k","line":11,"column":4,"end_line":11,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":10,"column":0,"end_line":13,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_main","filename":"config_expr-04.k","line":13,"column":0,"end_line":13,"end_column":5}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-04.k","line":13,"column":0,"end_line":13,"end_column":5}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Main","filename":"config_expr-04.k","line":13,"column":8,"end_line":13,"end_column":12}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":13,"column":8,"end_line":13,"end_column":12},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-04.k","line":14,"column":4,"end_line":14,"end_column":7}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":14,"column":4,"end_line":14,"end_column":7},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":13},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_1\"","value":"ENV_1"}},"filename":"config_expr-04.k","line":15,"column":15,"end_line":15,"end_column":22},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":22},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":29}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":29},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"1\"","value":"1"}},"filename":"config_expr-04.k","line":15,"column":31,"end_line":15,"end_column":34},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":34}]}},"filename":"config_expr-04.k","line":15,"column":8,"end_line":15,"end_column":35}],"ctx":"Load"}},"filename":"config_expr-04.k","line":14,"column":9,"end_line":16,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":14,"column":4,"end_line":16,"end_column":5}]}},"filename":"config_expr-04.k","line":13,"column":13,"end_line":17,"end_column":1}}},"filename":"config_expr-04.k","line":13,"column":8,"end_line":17,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-04.k","line":13,"column":0,"end_line":17,"end_column":1},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-04.k","line":19,"column":0,"end_line":19,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-04.k","line":19,"column":0,"end_line":19,"end_column":6}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Config","filename":"config_expr-04.k","line":19,"column":9,"end_line":19,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":19,"column":9,"end_line":19,"end_column":15},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":8},"value":{"node":{"Identifier":{"names":[{"node":"_main","filename":"config_expr-04.k","line":20,"column":10,"end_line":20,"end_column":15}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":20,"column":10,"end_line":20,"end_column":15},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":15},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-04.k","line":21,"column":4,"end_line":21,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":21,"column":4,"end_line":21,"end_column":8},"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Main","filename":"config_expr-04.k","line":21,"column":10,"end_line":21,"end_column":14}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":21,"column":10,"end_line":21,"end_column":14},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-04.k","line":22,"column":8,"end_line":22,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":22,"column":8,"end_line":22,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_2\"","value":"ENV_2"}},"filename":"config_expr-04.k","line":23,"column":19,"end_line":23,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"2\"","value":"2"}},"filename":"config_expr-04.k","line":23,"column":35,"end_line":23,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":38}]}},"filename":"config_expr-04.k","line":23,"column":12,"end_line":23,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-04.k","line":22,"column":15,"end_line":24,"end_column":9},"operation":"Insert","insert_index":-1},"filename":"config_expr-04.k","line":22,"column":8,"end_line":24,"end_column":9}]}},"filename":"config_expr-04.k","line":21,"column":15,"end_line":25,"end_column":5}}},"filename":"config_expr-04.k","line":21,"column":10,"end_line":25,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":21,"column":4,"end_line":25,"end_column":5}]}},"filename":"config_expr-04.k","line":19,"column":16,"end_line":26,"end_column":1}}},"filename":"config_expr-04.k","line":19,"column":9,"end_line":26,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-04.k","line":19,"column":0,"end_line":26,"end_column":1}],"comments":[{"node":{"text":"# test/grammar/attr_operator/config_inside/insert/schema_0/main.k"},"filename":"config_expr-04.k","line":1,"column":0,"end_line":1,"end_column":65}]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/config_expr-04.k\")" +--- +{"filename":"config_expr-04.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"Env","filename":"config_expr-04.k","line":3,"column":7,"end_line":3,"end_column":10},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"name","filename":"config_expr-04.k","line":4,"column":4,"end_line":4,"end_column":8},"type_str":{"node":"str","filename":"config_expr-04.k","line":4,"column":10,"end_line":4,"end_column":13},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"config_expr-04.k","line":4,"column":10,"end_line":4,"end_column":13}}},"filename":"config_expr-04.k","line":4,"column":4,"end_line":4,"end_column":13},{"node":{"SchemaAttr":{"doc":"","name":{"node":"value","filename":"config_expr-04.k","line":5,"column":4,"end_line":5,"end_column":9},"type_str":{"node":"str","filename":"config_expr-04.k","line":5,"column":11,"end_line":5,"end_column":14},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"config_expr-04.k","line":5,"column":11,"end_line":5,"end_column":14}}},"filename":"config_expr-04.k","line":5,"column":4,"end_line":5,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":3,"column":0,"end_line":7,"end_column":0},{"node":{"Schema":{"doc":"","name":{"node":"Main","filename":"config_expr-04.k","line":7,"column":7,"end_line":7,"end_column":11},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"env","filename":"config_expr-04.k","line":8,"column":4,"end_line":8,"end_column":7},"type_str":{"node":"[Env]","filename":"config_expr-04.k","line":8,"column":9,"end_line":8,"end_column":14},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"List":{"inner_type":{"node":{"Named":{"names":[{"node":"Env","filename":"config_expr-04.k","line":8,"column":10,"end_line":8,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":8,"column":10,"end_line":8,"end_column":13}}},"filename":"config_expr-04.k","line":8,"column":9,"end_line":8,"end_column":14}}},"filename":"config_expr-04.k","line":8,"column":4,"end_line":8,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":7,"column":0,"end_line":10,"end_column":0},{"node":{"Schema":{"doc":"","name":{"node":"Config","filename":"config_expr-04.k","line":10,"column":7,"end_line":10,"end_column":13},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"main","filename":"config_expr-04.k","line":11,"column":4,"end_line":11,"end_column":8},"type_str":{"node":"Main","filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14},"op":null,"value":null,"is_optional":false,"decorators":[],"ty":{"node":{"Named":{"names":[{"node":"Main","filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":11,"column":10,"end_line":11,"end_column":14}}},"filename":"config_expr-04.k","line":11,"column":4,"end_line":11,"end_column":14}],"decorators":[],"checks":[],"index_signature":null}},"filename":"config_expr-04.k","line":10,"column":0,"end_line":13,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"_main","filename":"config_expr-04.k","line":13,"column":0,"end_line":13,"end_column":5}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-04.k","line":13,"column":0,"end_line":13,"end_column":5}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Main","filename":"config_expr-04.k","line":13,"column":8,"end_line":13,"end_column":12}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":13,"column":8,"end_line":13,"end_column":12},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-04.k","line":14,"column":4,"end_line":14,"end_column":7}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":14,"column":4,"end_line":14,"end_column":7},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":13}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":13},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_1\"","value":"ENV_1"}},"filename":"config_expr-04.k","line":15,"column":15,"end_line":15,"end_column":22},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":15,"column":9,"end_line":15,"end_column":22},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":29}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":29},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"1\"","value":"1"}},"filename":"config_expr-04.k","line":15,"column":31,"end_line":15,"end_column":34},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":15,"column":24,"end_line":15,"end_column":34}]}},"filename":"config_expr-04.k","line":15,"column":8,"end_line":15,"end_column":35}],"ctx":"Load"}},"filename":"config_expr-04.k","line":14,"column":9,"end_line":16,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":14,"column":4,"end_line":16,"end_column":5}]}},"filename":"config_expr-04.k","line":13,"column":13,"end_line":17,"end_column":1}}},"filename":"config_expr-04.k","line":13,"column":8,"end_line":17,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-04.k","line":13,"column":0,"end_line":17,"end_column":1},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"config","filename":"config_expr-04.k","line":19,"column":0,"end_line":19,"end_column":6}],"pkgpath":"","ctx":"Store"},"filename":"config_expr-04.k","line":19,"column":0,"end_line":19,"end_column":6}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Config","filename":"config_expr-04.k","line":19,"column":9,"end_line":19,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":19,"column":9,"end_line":19,"end_column":15},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":8},"value":{"node":{"Identifier":{"names":[{"node":"_main","filename":"config_expr-04.k","line":20,"column":10,"end_line":20,"end_column":15}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":20,"column":10,"end_line":20,"end_column":15},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":20,"column":4,"end_line":20,"end_column":15},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"main","filename":"config_expr-04.k","line":21,"column":4,"end_line":21,"end_column":8}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":21,"column":4,"end_line":21,"end_column":8},"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Main","filename":"config_expr-04.k","line":21,"column":10,"end_line":21,"end_column":14}],"pkgpath":"","ctx":"Load"},"filename":"config_expr-04.k","line":21,"column":10,"end_line":21,"end_column":14},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"env","filename":"config_expr-04.k","line":22,"column":8,"end_line":22,"end_column":11}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":22,"column":8,"end_line":22,"end_column":11},"value":{"node":{"List":{"elts":[{"node":{"Config":{"items":[{"node":{"key":{"node":{"Identifier":{"names":[{"node":"name","filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":17}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":17},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"ENV_2\"","value":"ENV_2"}},"filename":"config_expr-04.k","line":23,"column":19,"end_line":23,"end_column":26},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":23,"column":13,"end_line":23,"end_column":26},{"node":{"key":{"node":{"Identifier":{"names":[{"node":"value","filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":33}],"pkgpath":"","ctx":"Load"}},"filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":33},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"2\"","value":"2"}},"filename":"config_expr-04.k","line":23,"column":35,"end_line":23,"end_column":38},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":23,"column":28,"end_line":23,"end_column":38}]}},"filename":"config_expr-04.k","line":23,"column":12,"end_line":23,"end_column":39}],"ctx":"Load"}},"filename":"config_expr-04.k","line":22,"column":15,"end_line":24,"end_column":9},"operation":"Insert","insert_index":-1},"filename":"config_expr-04.k","line":22,"column":8,"end_line":24,"end_column":9}]}},"filename":"config_expr-04.k","line":21,"column":15,"end_line":25,"end_column":5}}},"filename":"config_expr-04.k","line":21,"column":10,"end_line":25,"end_column":5},"operation":"Union","insert_index":-1},"filename":"config_expr-04.k","line":21,"column":4,"end_line":25,"end_column":5}]}},"filename":"config_expr-04.k","line":19,"column":16,"end_line":26,"end_column":1}}},"filename":"config_expr-04.k","line":19,"column":9,"end_line":26,"end_column":1},"type_annotation":null,"ty":null}},"filename":"config_expr-04.k","line":19,"column":0,"end_line":26,"end_column":1}],"comments":[{"node":{"text":"# test/grammar/attr_operator/config_inside/insert/schema_0/main.k"},"filename":"config_expr-04.k","line":1,"column":0,"end_line":1,"end_column":65}]} diff --git a/kclvm/parser/testdata/hello_win.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap similarity index 91% rename from kclvm/parser/testdata/hello_win.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap index ba85b5d17..2c5f11428 100644 --- a/kclvm/parser/testdata/hello_win.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__hello_win.snap @@ -1 +1,5 @@ -{"filename":"hello_win.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"Person","filename":"hello_win.k","line":2,"column":7,"end_line":2,"end_column":13},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"name","filename":"hello_win.k","line":3,"column":4,"end_line":3,"end_column":8},"type_str":{"node":"str","filename":"hello_win.k","line":3,"column":10,"end_line":3,"end_column":13},"op":{"Aug":"Assign"},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"kcl\"","value":"kcl"}},"filename":"hello_win.k","line":3,"column":16,"end_line":3,"end_column":21},"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello_win.k","line":3,"column":10,"end_line":3,"end_column":13}}},"filename":"hello_win.k","line":3,"column":4,"end_line":3,"end_column":21}],"decorators":[],"checks":[],"index_signature":null}},"filename":"hello_win.k","line":2,"column":0,"end_line":5,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"x0","filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":2}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Person","filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":11}],"pkgpath":"","ctx":"Load"},"filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":11},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[]}},"filename":"hello_win.k","line":5,"column":12,"end_line":5,"end_column":14}}},"filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":14},"type_annotation":null,"ty":null}},"filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":14}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/hello_win.k\")" +--- +{"filename":"hello_win.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Schema":{"doc":"","name":{"node":"Person","filename":"hello_win.k","line":2,"column":7,"end_line":2,"end_column":13},"parent_name":null,"for_host_name":null,"is_mixin":false,"is_protocol":false,"args":null,"mixins":[],"body":[{"node":{"SchemaAttr":{"doc":"","name":{"node":"name","filename":"hello_win.k","line":3,"column":4,"end_line":3,"end_column":8},"type_str":{"node":"str","filename":"hello_win.k","line":3,"column":10,"end_line":3,"end_column":13},"op":{"Aug":"Assign"},"value":{"node":{"StringLit":{"is_long_string":false,"raw_value":"\"kcl\"","value":"kcl"}},"filename":"hello_win.k","line":3,"column":16,"end_line":3,"end_column":21},"is_optional":false,"decorators":[],"ty":{"node":{"Basic":"Str"},"filename":"hello_win.k","line":3,"column":10,"end_line":3,"end_column":13}}},"filename":"hello_win.k","line":3,"column":4,"end_line":3,"end_column":21}],"decorators":[],"checks":[],"index_signature":null}},"filename":"hello_win.k","line":2,"column":0,"end_line":5,"end_column":0},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"x0","filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":2}],"pkgpath":"","ctx":"Store"},"filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":2}],"value":{"node":{"Schema":{"name":{"node":{"names":[{"node":"Person","filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":11}],"pkgpath":"","ctx":"Load"},"filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":11},"args":[],"kwargs":[],"config":{"node":{"Config":{"items":[]}},"filename":"hello_win.k","line":5,"column":12,"end_line":5,"end_column":14}}},"filename":"hello_win.k","line":5,"column":5,"end_line":5,"end_column":14},"type_annotation":null,"ty":null}},"filename":"hello_win.k","line":5,"column":0,"end_line":5,"end_column":14}],"comments":[]} diff --git a/kclvm/parser/testdata/if-01.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap similarity index 90% rename from kclvm/parser/testdata/if-01.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap index 47793d460..e7c4bc035 100644 --- a/kclvm/parser/testdata/if-01.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_1.snap @@ -1 +1,5 @@ -{"filename":"if-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-01.k","line":1,"column":4,"end_line":1,"end_column":5},"type_annotation":null,"ty":null}},"filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":5},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"bbb","filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"if-01.k","line":4,"column":10,"end_line":4,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":11}],"cond":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-01.k","line":3,"column":3,"end_line":3,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"if-01.k","line":3,"column":3,"end_line":3,"end_column":4},"orelse":[]}},"filename":"if-01.k","line":3,"column":0,"end_line":4,"end_column":12}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/if-01.k\")" +--- +{"filename":"if-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-01.k","line":1,"column":4,"end_line":1,"end_column":5},"type_annotation":null,"ty":null}},"filename":"if-01.k","line":1,"column":0,"end_line":1,"end_column":5},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"bbb","filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"if-01.k","line":4,"column":10,"end_line":4,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-01.k","line":4,"column":4,"end_line":4,"end_column":11}],"cond":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-01.k","line":3,"column":3,"end_line":3,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"if-01.k","line":3,"column":3,"end_line":3,"end_column":4},"orelse":[]}},"filename":"if-01.k","line":3,"column":0,"end_line":4,"end_column":12}],"comments":[]} diff --git a/kclvm/parser/testdata/if-02.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap similarity index 97% rename from kclvm/parser/testdata/if-02.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap index cf1934081..68be5b623 100644 --- a/kclvm/parser/testdata/if-02.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_2.snap @@ -1 +1,5 @@ -{"filename":"if-02.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-02.k","line":1,"column":4,"end_line":1,"end_column":5},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":5},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"bbb","filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"if-02.k","line":4,"column":10,"end_line":4,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":11}],"cond":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":3,"column":3,"end_line":3,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":3,"column":3,"end_line":3,"end_column":4},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"ccc","filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"if-02.k","line":6,"column":10,"end_line":6,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":11}],"cond":{"node":{"Binary":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":6},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"if-02.k","line":5,"column":9,"end_line":5,"end_column":11}}},"filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":11},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"ddd","filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":4}}},"filename":"if-02.k","line":8,"column":10,"end_line":8,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":11}],"cond":{"node":{"Binary":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":6},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":100}}},"filename":"if-02.k","line":7,"column":9,"end_line":7,"end_column":12}}},"filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":12},"orelse":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"eee","filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":5}}},"filename":"if-02.k","line":10,"column":10,"end_line":10,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":11},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"fff","filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":6}}},"filename":"if-02.k","line":11,"column":10,"end_line":11,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":7,"column":0,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":5,"column":0,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":3,"column":0,"end_line":11,"end_column":12}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/if-02.k\")" +--- +{"filename":"if-02.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":1}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":1}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-02.k","line":1,"column":4,"end_line":1,"end_column":5},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":1,"column":0,"end_line":1,"end_column":5},{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"bbb","filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":2}}},"filename":"if-02.k","line":4,"column":10,"end_line":4,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":4,"column":4,"end_line":4,"end_column":11}],"cond":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":3,"column":3,"end_line":3,"end_column":4}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":3,"column":3,"end_line":3,"end_column":4},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"ccc","filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":3}}},"filename":"if-02.k","line":6,"column":10,"end_line":6,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":6,"column":4,"end_line":6,"end_column":11}],"cond":{"node":{"Binary":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":6},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":10}}},"filename":"if-02.k","line":5,"column":9,"end_line":5,"end_column":11}}},"filename":"if-02.k","line":5,"column":5,"end_line":5,"end_column":11},"orelse":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"ddd","filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":4}}},"filename":"if-02.k","line":8,"column":10,"end_line":8,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":8,"column":4,"end_line":8,"end_column":11}],"cond":{"node":{"Binary":{"left":{"node":{"Identifier":{"names":[{"node":"a","filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":6}],"pkgpath":"","ctx":"Load"}},"filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":6},"op":{"Bin":"Add"},"right":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":100}}},"filename":"if-02.k","line":7,"column":9,"end_line":7,"end_column":12}}},"filename":"if-02.k","line":7,"column":5,"end_line":7,"end_column":12},"orelse":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"eee","filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":5}}},"filename":"if-02.k","line":10,"column":10,"end_line":10,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":10,"column":4,"end_line":10,"end_column":11},{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"fff","filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":7}],"pkgpath":"","ctx":"Store"},"filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":7}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":6}}},"filename":"if-02.k","line":11,"column":10,"end_line":11,"end_column":11},"type_annotation":null,"ty":null}},"filename":"if-02.k","line":11,"column":4,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":7,"column":0,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":5,"column":0,"end_line":11,"end_column":11}]}},"filename":"if-02.k","line":3,"column":0,"end_line":11,"end_column":12}],"comments":[]} diff --git a/kclvm/parser/testdata/if-03.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap similarity index 84% rename from kclvm/parser/testdata/if-03.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap index c46bdb72e..d37ca8119 100644 --- a/kclvm/parser/testdata/if-03.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__if_3.snap @@ -1 +1,5 @@ -{"filename":"if-03.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":10}],"pkgpath":"","ctx":"Store"},"filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":10}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-03.k","line":1,"column":13,"end_line":1,"end_column":14},"type_annotation":null,"ty":null}},"filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":14}],"cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"if-03.k","line":1,"column":3,"end_line":1,"end_column":7},"orelse":[]}},"filename":"if-03.k","line":1,"column":0,"end_line":1,"end_column":15}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/if-03.k\")" +--- +{"filename":"if-03.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"If":{"body":[{"node":{"Assign":{"targets":[{"node":{"names":[{"node":"a","filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":10}],"pkgpath":"","ctx":"Store"},"filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":10}],"value":{"node":{"NumberLit":{"binary_suffix":null,"value":{"Int":1}}},"filename":"if-03.k","line":1,"column":13,"end_line":1,"end_column":14},"type_annotation":null,"ty":null}},"filename":"if-03.k","line":1,"column":9,"end_line":1,"end_column":14}],"cond":{"node":{"NameConstantLit":{"value":"True"}},"filename":"if-03.k","line":1,"column":3,"end_line":1,"end_column":7},"orelse":[]}},"filename":"if-03.k","line":1,"column":0,"end_line":1,"end_column":15}],"comments":[]} diff --git a/kclvm/parser/testdata/import-01.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap similarity index 87% rename from kclvm/parser/testdata/import-01.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap index d78fce55b..c8cc16d01 100644 --- a/kclvm/parser/testdata/import-01.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__import_1.snap @@ -1 +1,5 @@ +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/import-01.k\")" +--- {"filename":"import-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"Import":{"path":"a1","rawpath":"a1","name":"a1","asname":null,"pkg_name":""}},"filename":"import-01.k","line":1,"column":0,"end_line":1,"end_column":9},{"node":{"Import":{"path":"a2","rawpath":"a2","name":"a2_pkg","asname":"a2_pkg","pkg_name":""}},"filename":"import-01.k","line":3,"column":0,"end_line":3,"end_column":19},{"node":{"Import":{"path":"subpkg.b1.c1","rawpath":"subpkg.b1.c1","name":"c1","asname":null,"pkg_name":""}},"filename":"import-01.k","line":5,"column":0,"end_line":5,"end_column":19},{"node":{"Import":{"path":".a3","rawpath":".a3","name":"a3","asname":null,"pkg_name":""}},"filename":"import-01.k","line":7,"column":0,"end_line":7,"end_column":10}],"comments":[]} diff --git a/kclvm/parser/testdata/type-01.k.json b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap similarity index 97% rename from kclvm/parser/testdata/type-01.k.json rename to kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap index c1c9b5164..e4b1166b1 100644 --- a/kclvm/parser/testdata/type-01.k.json +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__file__type_1.snap @@ -1 +1,5 @@ -{"filename":"type-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"a","filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":6},"type_value":{"node":"any","filename":"type-01.k","line":1,"column":9,"end_line":1,"end_column":12},"ty":{"node":"Any","filename":"type-01.k","line":1,"column":9,"end_line":1,"end_column":12}}},"filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"b","filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":6},"type_value":{"node":"bool","filename":"type-01.k","line":3,"column":9,"end_line":3,"end_column":13},"ty":{"node":{"Basic":"Bool"},"filename":"type-01.k","line":3,"column":9,"end_line":3,"end_column":13}}},"filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":13},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"c","filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":6},"type_value":{"node":"int","filename":"type-01.k","line":4,"column":9,"end_line":4,"end_column":12},"ty":{"node":{"Basic":"Int"},"filename":"type-01.k","line":4,"column":9,"end_line":4,"end_column":12}}},"filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"d","filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":6},"type_value":{"node":"float","filename":"type-01.k","line":5,"column":9,"end_line":5,"end_column":14},"ty":{"node":{"Basic":"Float"},"filename":"type-01.k","line":5,"column":9,"end_line":5,"end_column":14}}},"filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":14},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"e","filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":6},"type_value":{"node":"str","filename":"type-01.k","line":6,"column":9,"end_line":6,"end_column":12},"ty":{"node":{"Basic":"Str"},"filename":"type-01.k","line":6,"column":9,"end_line":6,"end_column":12}}},"filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list1","filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":15},"type_value":{"node":"[]","filename":"type-01.k","line":8,"column":18,"end_line":8,"end_column":20},"ty":{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":8,"column":18,"end_line":8,"end_column":20}}},"filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":20},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list2","filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":15},"type_value":{"node":"[[]]","filename":"type-01.k","line":9,"column":18,"end_line":9,"end_column":22},"ty":{"node":{"List":{"inner_type":{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":9,"column":19,"end_line":9,"end_column":21}}},"filename":"type-01.k","line":9,"column":18,"end_line":9,"end_column":22}}},"filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":22},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list3","filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":15},"type_value":{"node":"[int]","filename":"type-01.k","line":10,"column":18,"end_line":10,"end_column":23},"ty":{"node":{"List":{"inner_type":{"node":{"Basic":"Int"},"filename":"type-01.k","line":10,"column":19,"end_line":10,"end_column":22}}},"filename":"type-01.k","line":10,"column":18,"end_line":10,"end_column":23}}},"filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":23},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"b","filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":6},"type_value":{"node":"int | str | [] | {:}","filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":29},"ty":{"node":{"Union":{"type_elements":[{"node":{"Basic":"Int"},"filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":12},{"node":{"Basic":"Str"},"filename":"type-01.k","line":12,"column":15,"end_line":12,"end_column":18},{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":12,"column":21,"end_line":12,"end_column":23},{"node":{"Dict":{"key_type":null,"value_type":null}},"filename":"type-01.k","line":12,"column":26,"end_line":12,"end_column":29}]}},"filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":29}}},"filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":29}],"comments":[]} \ No newline at end of file +--- +source: parser/src/tests/file.rs +expression: "crate::tests::parsing_file_string(\"testdata/type-01.k\")" +--- +{"filename":"type-01.k","pkg":"__main__","doc":"","name":"__main__","body":[{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"a","filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":6},"type_value":{"node":"any","filename":"type-01.k","line":1,"column":9,"end_line":1,"end_column":12},"ty":{"node":"Any","filename":"type-01.k","line":1,"column":9,"end_line":1,"end_column":12}}},"filename":"type-01.k","line":1,"column":5,"end_line":1,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"b","filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":6},"type_value":{"node":"bool","filename":"type-01.k","line":3,"column":9,"end_line":3,"end_column":13},"ty":{"node":{"Basic":"Bool"},"filename":"type-01.k","line":3,"column":9,"end_line":3,"end_column":13}}},"filename":"type-01.k","line":3,"column":5,"end_line":3,"end_column":13},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"c","filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":6},"type_value":{"node":"int","filename":"type-01.k","line":4,"column":9,"end_line":4,"end_column":12},"ty":{"node":{"Basic":"Int"},"filename":"type-01.k","line":4,"column":9,"end_line":4,"end_column":12}}},"filename":"type-01.k","line":4,"column":5,"end_line":4,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"d","filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":6},"type_value":{"node":"float","filename":"type-01.k","line":5,"column":9,"end_line":5,"end_column":14},"ty":{"node":{"Basic":"Float"},"filename":"type-01.k","line":5,"column":9,"end_line":5,"end_column":14}}},"filename":"type-01.k","line":5,"column":5,"end_line":5,"end_column":14},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"e","filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":6},"type_value":{"node":"str","filename":"type-01.k","line":6,"column":9,"end_line":6,"end_column":12},"ty":{"node":{"Basic":"Str"},"filename":"type-01.k","line":6,"column":9,"end_line":6,"end_column":12}}},"filename":"type-01.k","line":6,"column":5,"end_line":6,"end_column":12},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list1","filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":15},"type_value":{"node":"[]","filename":"type-01.k","line":8,"column":18,"end_line":8,"end_column":20},"ty":{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":8,"column":18,"end_line":8,"end_column":20}}},"filename":"type-01.k","line":8,"column":5,"end_line":8,"end_column":20},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list2","filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":15},"type_value":{"node":"[[]]","filename":"type-01.k","line":9,"column":18,"end_line":9,"end_column":22},"ty":{"node":{"List":{"inner_type":{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":9,"column":19,"end_line":9,"end_column":21}}},"filename":"type-01.k","line":9,"column":18,"end_line":9,"end_column":22}}},"filename":"type-01.k","line":9,"column":5,"end_line":9,"end_column":22},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"type_list3","filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":15}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":15},"type_value":{"node":"[int]","filename":"type-01.k","line":10,"column":18,"end_line":10,"end_column":23},"ty":{"node":{"List":{"inner_type":{"node":{"Basic":"Int"},"filename":"type-01.k","line":10,"column":19,"end_line":10,"end_column":22}}},"filename":"type-01.k","line":10,"column":18,"end_line":10,"end_column":23}}},"filename":"type-01.k","line":10,"column":5,"end_line":10,"end_column":23},{"node":{"TypeAlias":{"type_name":{"node":{"names":[{"node":"b","filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":6}],"pkgpath":"","ctx":"Load"},"filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":6},"type_value":{"node":"int | str | [] | {:}","filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":29},"ty":{"node":{"Union":{"type_elements":[{"node":{"Basic":"Int"},"filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":12},{"node":{"Basic":"Str"},"filename":"type-01.k","line":12,"column":15,"end_line":12,"end_column":18},{"node":{"List":{"inner_type":null}},"filename":"type-01.k","line":12,"column":21,"end_line":12,"end_column":23},{"node":{"Dict":{"key_type":null,"value_type":null}},"filename":"type-01.k","line":12,"column":26,"end_line":12,"end_column":29}]}},"filename":"type-01.k","line":12,"column":9,"end_line":12,"end_column":29}}},"filename":"type-01.k","line":12,"column":5,"end_line":12,"end_column":29}],"comments":[]} diff --git a/kclvm/parser/testdata/Makefile b/kclvm/parser/testdata/Makefile deleted file mode 100644 index ac278ac6b..000000000 --- a/kclvm/parser/testdata/Makefile +++ /dev/null @@ -1,13 +0,0 @@ - -K_FILES=$(wildcard ./*.k) -K_JSON_FILES=$(patsubst %.k,%.k.json,$(K_FILES)) - -default: clean $(K_JSON_FILES) $(K_FMT_JSON_FILES) - @echo "ok" - -clean: - -rm *.k.json - -%.k.json: %.k - cargo run --bin parse_file $< > $@ -