1
0

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]
fn map() {
let map = Map::new();
@ -56,6 +61,11 @@ fn 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]
fn map_types() {
let map = Map::new();
@ -119,7 +129,5 @@ fn option() {
#[test]
fn range() {
let result = interpret("0..100");
assert_eq!(Ok(Value::range(0, 100)), result);
assert_eq!(interpret("0..100"), Ok(Value::range(0, 100)));
}

View File

@ -263,20 +263,23 @@ module.exports = grammar({
),
map: $ =>
seq(
'{',
repeat1(
seq(
$.identifier,
optional(
$.type_specification,
prec(
1,
seq(
'{',
repeat(
seq(
$.identifier,
optional(
$.type_specification,
),
'=',
$.statement,
optional(','),
),
'=',
$.statement,
optional(','),
),
'}',
),
'}',
),
option: $ =>

View File

@ -769,61 +769,65 @@
]
},
"map": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_specification"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_specification"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "statement"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "STRING",
"value": "}"
}
},
{
"type": "STRING",
"value": "}"
}
]
]
}
},
"option": {
"type": "CHOICE",

View File

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

File diff suppressed because it is too large Load Diff