-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: schema optional attribute validating recursively
Signed-off-by: peefy <[email protected]>
- Loading branch information
Showing
16 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,5 @@ pub use val_union::*; | |
|
||
pub mod val_yaml; | ||
pub use val_yaml::*; | ||
|
||
pub mod walker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::{Value, ValueRef}; | ||
|
||
/// Walk the value recursively and deal the type using the `walk_fn` | ||
pub fn walk_value(val: &ValueRef, walk_fn: &impl Fn(&ValueRef) -> ()) { | ||
walk_fn(val); | ||
match &*val.rc.borrow() { | ||
Value::list_value(list_value) => { | ||
for v in &list_value.values { | ||
walk_value(v, walk_fn); | ||
} | ||
} | ||
Value::dict_value(dict_value) => { | ||
for (_, v) in &dict_value.values { | ||
walk_value(v, walk_fn); | ||
} | ||
} | ||
Value::schema_value(schema_value) => { | ||
for (_, v) in &schema_value.config.values { | ||
walk_value(v, walk_fn); | ||
} | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
/// Walk the value recursively and mutably and deal the type using the `walk_fn` | ||
pub fn walk_value_mut(val: &ValueRef, walk_fn: &mut impl FnMut(&ValueRef) -> ()) { | ||
walk_fn(val); | ||
match &*val.rc.borrow() { | ||
Value::list_value(list_value) => { | ||
for v in &list_value.values { | ||
walk_value_mut(v, walk_fn); | ||
} | ||
} | ||
Value::dict_value(dict_value) => { | ||
for (_, v) in &dict_value.values { | ||
walk_value_mut(v, walk_fn); | ||
} | ||
} | ||
Value::schema_value(schema_value) => { | ||
for (_, v) in &schema_value.config.values { | ||
walk_value_mut(v, walk_fn); | ||
} | ||
} | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
schema Data: | ||
name: str | ||
type: str | ||
|
||
data = { | ||
name = "data" | ||
} | ||
|
||
datas: [Data] = [data] |
18 changes: 18 additions & 0 deletions
18
test/grammar/schema/optional_attr/fail_15/stderr.golden.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sys | ||
import os | ||
|
||
import kclvm.kcl.error as kcl_error | ||
|
||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
kcl_error.print_kcl_error_message( | ||
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE, | ||
file_msgs=[ | ||
kcl_error.ErrFileMsg( | ||
filename=os.path.join(cwd, "main.k"), | ||
line_no=9, | ||
), | ||
], | ||
arg_msg="attribute 'type' of Data is required and can't be None or Undefined") | ||
, file=sys.stdout | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
schema Data: | ||
name: str | ||
type: str | ||
|
||
data = { | ||
name = "data" | ||
} | ||
|
||
datas: [[Data]] = [[data]] |
18 changes: 18 additions & 0 deletions
18
test/grammar/schema/optional_attr/fail_16/stderr.golden.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sys | ||
import os | ||
|
||
import kclvm.kcl.error as kcl_error | ||
|
||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
kcl_error.print_kcl_error_message( | ||
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE, | ||
file_msgs=[ | ||
kcl_error.ErrFileMsg( | ||
filename=os.path.join(cwd, "main.k"), | ||
line_no=9, | ||
), | ||
], | ||
arg_msg="attribute 'type' of Data is required and can't be None or Undefined") | ||
, file=sys.stdout | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
schema Data: | ||
name: str | ||
type: str | ||
|
||
data = { | ||
name = "data" | ||
} | ||
|
||
datas: {str:Data} = { | ||
data = data | ||
} |
18 changes: 18 additions & 0 deletions
18
test/grammar/schema/optional_attr/fail_17/stderr.golden.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sys | ||
import os | ||
|
||
import kclvm.kcl.error as kcl_error | ||
|
||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
kcl_error.print_kcl_error_message( | ||
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE, | ||
file_msgs=[ | ||
kcl_error.ErrFileMsg( | ||
filename=os.path.join(cwd, "main.k"), | ||
line_no=10, | ||
), | ||
], | ||
arg_msg="attribute 'type' of Data is required and can't be None or Undefined") | ||
, file=sys.stdout | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
schema Data: | ||
name: str | ||
type: str | ||
|
||
data = { | ||
name = "data" | ||
} | ||
|
||
datas: {str:{str:Data}} = { | ||
data.data = data | ||
} |
18 changes: 18 additions & 0 deletions
18
test/grammar/schema/optional_attr/fail_18/stderr.golden.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sys | ||
import os | ||
|
||
import kclvm.kcl.error as kcl_error | ||
|
||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
kcl_error.print_kcl_error_message( | ||
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE, | ||
file_msgs=[ | ||
kcl_error.ErrFileMsg( | ||
filename=os.path.join(cwd, "main.k"), | ||
line_no=10, | ||
), | ||
], | ||
arg_msg="attribute 'type' of Data is required and can't be None or Undefined") | ||
, file=sys.stdout | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
schema Data: | ||
name: str | ||
type: str | ||
|
||
data = { | ||
name = "data" | ||
} | ||
|
||
datas: {str:[Data]} = { | ||
data = [data] | ||
} |
18 changes: 18 additions & 0 deletions
18
test/grammar/schema/optional_attr/fail_19/stderr.golden.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sys | ||
import os | ||
|
||
import kclvm.kcl.error as kcl_error | ||
|
||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
kcl_error.print_kcl_error_message( | ||
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE, | ||
file_msgs=[ | ||
kcl_error.ErrFileMsg( | ||
filename=os.path.join(cwd, "main.k"), | ||
line_no=10, | ||
), | ||
], | ||
arg_msg="attribute 'type' of Data is required and can't be None or Undefined") | ||
, file=sys.stdout | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
schema Data: | ||
name: str | ||
type: str | ||
|
||
data = { | ||
name = "data" | ||
} | ||
|
||
datas: [{str:[Data]}] = [{ | ||
data = [data] | ||
}] |
18 changes: 18 additions & 0 deletions
18
test/grammar/schema/optional_attr/fail_20/stderr.golden.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sys | ||
import os | ||
|
||
import kclvm.kcl.error as kcl_error | ||
|
||
cwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
kcl_error.print_kcl_error_message( | ||
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE, | ||
file_msgs=[ | ||
kcl_error.ErrFileMsg( | ||
filename=os.path.join(cwd, "main.k"), | ||
line_no=10, | ||
), | ||
], | ||
arg_msg="attribute 'type' of Data is required and can't be None or Undefined") | ||
, file=sys.stdout | ||
) |