Allow empty maps; Write tests

This commit is contained in:
Jeff 2024-01-29 17:36:21 -05:00
parent bd6ca6a6c1
commit df5cf93e58
5 changed files with 21112 additions and 20638 deletions

View File

@ -45,6 +45,11 @@ fn list() {
); );
} }
#[test]
fn empty_list() {
assert_eq!(interpret("[]"), Ok(Value::List(List::new())));
}
#[test] #[test]
fn map() { fn map() {
let map = Map::new(); let map = Map::new();
@ -56,6 +61,11 @@ fn map() {
assert_eq!(interpret("{ x = 1, foo = 'bar' }"), Ok(Value::Map(map))); assert_eq!(interpret("{ x = 1, foo = 'bar' }"), Ok(Value::Map(map)));
} }
#[test]
fn empty_map() {
assert_eq!(interpret("{}"), Ok(Value::Map(Map::new())));
}
#[test] #[test]
fn map_types() { fn map_types() {
let map = Map::new(); let map = Map::new();
@ -119,7 +129,5 @@ fn option() {
#[test] #[test]
fn range() { fn range() {
let result = interpret("0..100"); assert_eq!(interpret("0..100"), Ok(Value::range(0, 100)));
assert_eq!(Ok(Value::range(0, 100)), result);
} }

View File

@ -263,9 +263,11 @@ module.exports = grammar({
), ),
map: $ => map: $ =>
prec(
1,
seq( seq(
'{', '{',
repeat1( repeat(
seq( seq(
$.identifier, $.identifier,
optional( optional(
@ -278,6 +280,7 @@ module.exports = grammar({
), ),
'}', '}',
), ),
),
option: $ => option: $ =>
choice( choice(

View File

@ -769,6 +769,9 @@
] ]
}, },
"map": { "map": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -776,7 +779,7 @@
"value": "{" "value": "{"
}, },
{ {
"type": "REPEAT1", "type": "REPEAT",
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -824,6 +827,7 @@
"value": "}" "value": "}"
} }
] ]
}
}, },
"option": { "option": {
"type": "CHOICE", "type": "CHOICE",

View File

@ -413,7 +413,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "identifier", "type": "identifier",

File diff suppressed because it is too large Load Diff