Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion test/syntax-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"{{}",
"{{}}}",
"{|foo| #markup}",
"{/tag foo=bar}",
"{{missing end brace}",
"{{missing end braces",
"{{missing end {$braces",
Expand All @@ -17,6 +16,10 @@
"missing space {|foo|:func}",
"missing space {|foo|@bar}",
"missing space {:func@bar}",
"missing space {:func @bar@baz}",
"missing space {:func @bar=42@baz}",
"missing space {+reserved@bar}",
"missing space {&private@bar}",
Comment on lines +19 to +22
Copy link
Collaborator

@gibson042 gibson042 Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem like "missing space".

Suggested change
"missing space {:func @bar@baz}",
"missing space {:func @bar=42@baz}",
"missing space {+reserved@bar}",
"missing space {&private@bar}",
"missing equals {:func @bar@baz}",
"missing quotes {:func @bar=42@baz}",
"reserved {+reserved@bar}",
"private {&private@bar}",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of those can be turned into valid syntax with the addition of a single space:

Suggested change
"missing space {:func @bar@baz}",
"missing space {:func @bar=42@baz}",
"missing space {+reserved@bar}",
"missing space {&private@bar}",
"missing space {:func @bar @baz}",
"missing space {:func @bar=42 @baz}",
"missing space {+reserved @bar}",
"missing space {&private @bar}",

(the above is not intended as an actual suggestion, just to show a nice diff)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, though, they are invalid name tests. You created them by removing non-optional spaces, of course.

"bad {:} placeholder",
"bad {\\u0000placeholder}",
"no-equal {|42| :number minimumFractionDigits 2}",
Expand Down
72 changes: 72 additions & 0 deletions test/test-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@
}
]
},
{
"src": "{#tag foo=bar/}",
"cleanSrc": "{#tag foo=bar /}",
"exp": "",
"parts": [
{
"type": "markup",
"kind": "standalone",
"name": "tag",
"options": { "foo": "bar" }
}
]
},
{
"src": "{#tag a:foo=|foo| b:bar=$bar}",
"params": { "bar": "b a r" },
Expand All @@ -127,6 +140,18 @@
}
]
},
{
"src": "{/tag foo=bar}",
"exp": "",
"parts": [
{
"type": "markup",
"kind": "close",
"name": "tag",
"options": { "foo": "bar" }
}
]
},
{
"src": "{42 @foo @bar=13}",
"exp": "42",
Expand All @@ -136,5 +161,52 @@
"src": "{42 @foo=$bar}",
"exp": "42",
"parts": [{ "type": "string", "value": "42" }]
},
{
"src": "foo {+reserved}",
"exp": "foo {+}",
"parts": [
{ "type": "literal", "value": "foo " },
{ "type": "fallback", "source": "+" }
],
"errors": [{ "type": "unsupported-annotation" }]
},
{
"src": "foo {&private}",
"exp": "foo {&}",
"parts": [
{ "type": "literal", "value": "foo " },
{ "type": "fallback", "source": "&" }
],
"errors": [{ "type": "unsupported-annotation" }]
},
{
"src": "foo {?reserved @a @b=$c}",
"exp": "foo {?}",
"parts": [
{ "type": "literal", "value": "foo " },
{ "type": "fallback", "source": "?" }
],
"errors": [{ "type": "unsupported-annotation" }]
},
{
"src": ".foo {42} {{bar}}",
"exp": "bar",
"parts": [{ "type": "literal", "value": "bar" }],
"errors": [{ "type": "unsupported-statement" }]
},
{
"src": ".foo{42}{{bar}}",
"cleanSrc": ".foo {42} {{bar}}",
"exp": "bar",
"parts": [{ "type": "literal", "value": "bar" }],
"errors": [{ "type": "unsupported-statement" }]
},
{
"src": ".foo |}lit{| {42}{{bar}}",
"cleanSrc": ".foo |}lit{| {42} {{bar}}",
"exp": "bar",
"parts": [{ "type": "literal", "value": "bar" }],
"errors": [{ "type": "unsupported-statement" }]
}
]
111 changes: 87 additions & 24 deletions test/test-functions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,85 @@
{
"date": [
{ "src": "{:date}", "exp": "{:date}", "errors": [{ "type": "bad-input" }] },
{
"src": "{horse :date}",
"exp": "{|horse|}",
"errors": [{ "name": "RangeError" }]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the spec says this should be an invalid expression error. Your code might call this a RangeError. Fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true. I currently don't add a wrapper for the built in JS RangeError that's the cause here, as the :number spec requires.

},
{ "src": "{|2006-01-02| :date}", "exp": "1/2/06" },
{ "src": "{|2006-01-02T15:04:06| :date}", "exp": "1/2/06" },
{ "src": "{|2006-01-02| :date style=long}", "exp": "January 2, 2006" },
{
"src": ".local $d = {|2006-01-02| :date style=long} {{{$d :date}}}",
"exp": "January 2, 2006"
},
{
"src": ".local $t = {|2006-01-02T15:04:06| :time} {{{$t :date}}}",
"exp": "1/2/06"
}
],
"time": [
{ "src": "{:time}", "exp": "{:time}", "errors": [{ "type": "bad-input" }] },
{
"src": "{horse :time}",
"exp": "{|horse|}",
"errors": [{ "name": "RangeError" }]
},
{ "src": "{|2006-01-02T15:04:06| :time}", "exp": "3:04 PM" },
{
"src": "{|2006-01-02T15:04:06| :time style=medium}",
"exp": "3:04:06 PM"
},
{
"src": ".local $t = {|2006-01-02T15:04:06| :time style=medium} {{{$t :time}}}",
"exp": "3:04:06 PM"
},
{
"src": ".local $d = {|2006-01-02T15:04:06| :date} {{{$d :time}}}",
"exp": "3:04 PM"
}
],
"datetime": [
{
"src": "{:datetime}",
"exp": "{:datetime}",
"errors": [{ "type": "bad-input" }]
},
{
"src": "{$x :datetime}",
"exp": "{$x}",
"params": { "x": true },
"errors": [{ "type": "bad-input" }]
},
{
"src": "{horse :datetime}",
"exp": "{|horse|}",
"errors": [{ "name": "RangeError" }]
},
{ "src": "{|2006-01-02T15:04:06| :datetime}", "exp": "1/2/06, 3:04 PM" },
{
"src": "{|2006-01-02T15:04:06| :datetime year=numeric month=|2-digit|}",
"exp": "01/2006"
},
{
"src": "{|2006-01-02T15:04:06| :datetime dateStyle=long}",
"exp": "January 2, 2006"
},
{
"src": "{|2006-01-02T15:04:06| :datetime timeStyle=medium}",
"exp": "3:04:06 PM"
},
{
"src": "{$dt :datetime}",
"params": { "dt": "2006-01-02T15:04:06" },
"exp": "1/2/06, 3:04 PM"
},
{
"src": ".input {$dt :time style=medium} {{{$dt :datetime dateStyle=long}}}",
"params": { "dt": "2006-01-02T15:04:06" },
"exp": "January 2, 2006 at 3:04:06 PM"
}
],
"integer": [
{ "src": "hello {4.2 :integer}", "exp": "hello 4" },
{ "src": "hello {-4.20 :integer}", "exp": "hello -4" },
Expand Down Expand Up @@ -194,44 +275,26 @@
{
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
"params": { "foo": 1 },
"exp": "st"
},
{
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
"params": { "foo": 2 },
"exp": "nd"
},
{
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
"params": { "foo": 3 },
"exp": "rd"
},
{
"src": ".match {$foo :ordinal} one {{st}} two {{nd}} few {{rd}} * {{th}}",
"params": { "foo": 4 },
"exp": "th"
"exp": "th",
"errors": [{ "type": "missing-func" }, { "type": "not-selectable" }]
},
{
"src": "hello {42 :ordinal}",
"exp": "hello {|42|}",
"errors": [{ "type": "not-formattable" }]
"errors": [{ "type": "missing-func" }]
}
],
"plural": [
{
"src": ".match {$foo :plural} one {{one}} * {{other}}",
"params": { "foo": 1 },
"exp": "one"
},
{
"src": ".match {$foo :plural} one {{one}} * {{other}}",
"params": { "foo": 1.1 },
"exp": "other"
"exp": "other",
"errors": [{ "type": "missing-func" }, { "type": "not-selectable" }]
},
{
"src": "hello {42 :plural}",
"exp": "hello {|42|}",
"errors": [{ "type": "not-formattable" }]
"errors": [{ "type": "missing-func" }]
}
],
"string": [
Expand Down