aboutsummaryrefslogtreecommitdiff
path: root/compiler/parser_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-04-30 01:54:02 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-04-30 01:54:02 +0900
commit43fdbf94ad87ea91a173c72688cad70a0a5f1ab4 (patch)
tree655f651e39f13b5e415445d1ef24f4ecb7511041 /compiler/parser_test.go
parentAdd code point expression (Meet RL1.1 of UTS #18) (diff)
downloadtre-43fdbf94ad87ea91a173c72688cad70a0a5f1ab4.tar.gz
tre-43fdbf94ad87ea91a173c72688cad70a0a5f1ab4.tar.xz
Add character property expression (Meet RL1.2 of UTS #18 partially)
\p{property name=property value} matches a character has the property. When the property name is General_Category, it can be omitted. That is, \p{Letter} equals \p{General_Category=Letter}. Currently, only General_Category is supported. This feature meets RL1.2 of UTS #18 partially. RL1.2 Properties: https://unicode.org/reports/tr18/#RL1.2
Diffstat (limited to 'compiler/parser_test.go')
-rw-r--r--compiler/parser_test.go73
1 files changed, 72 insertions, 1 deletions
diff --git a/compiler/parser_test.go b/compiler/parser_test.go
index c636d8b..5a138ab 100644
--- a/compiler/parser_test.go
+++ b/compiler/parser_test.go
@@ -29,6 +29,11 @@ func TestParser_parse(t *testing.T) {
pattern string
ast astNode
syntaxError *SyntaxError
+
+ // When an AST is large, as patterns containing a character property expression,
+ // this test only checks that the pattern is parsable.
+ // The check of the validity of such AST is performed by checking that it can be matched correctly using the driver.
+ skipTestAST bool
}{
{
pattern: "a",
@@ -84,6 +89,10 @@ func TestParser_parse(t *testing.T) {
),
},
{
+ pattern: "\\p{Letter}?",
+ skipTestAST: true,
+ },
+ {
pattern: "(a)?",
ast: genConcatNode(
newOptionNode(
@@ -186,6 +195,10 @@ func TestParser_parse(t *testing.T) {
),
},
{
+ pattern: "\\p{Letter}*",
+ skipTestAST: true,
+ },
+ {
pattern: "((a*)*)*",
ast: genConcatNode(
newRepeatNode(
@@ -290,6 +303,10 @@ func TestParser_parse(t *testing.T) {
),
},
{
+ pattern: "\\p{Letter}+",
+ skipTestAST: true,
+ },
+ {
pattern: "((a+)+)+",
ast: genConcatNode(
genConcatNode(
@@ -838,6 +855,58 @@ func TestParser_parse(t *testing.T) {
syntaxError: synErrCPExpInvalidForm,
},
{
+ pattern: "\\p{Letter}",
+ skipTestAST: true,
+ },
+ {
+ pattern: "\\p{General_Category=Letter}",
+ skipTestAST: true,
+ },
+ {
+ pattern: "\\p{ Letter }",
+ skipTestAST: true,
+ },
+ {
+ pattern: "\\p{ General_Category = Letter }",
+ skipTestAST: true,
+ },
+ {
+ pattern: "\\p",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
+ pattern: "\\p{",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
+ pattern: "\\p{Letter",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
+ pattern: "\\p{General_Category=}",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
+ pattern: "\\p{General_Category= }",
+ syntaxError: synErrCharPropInvalidSymbol,
+ },
+ {
+ pattern: "\\p{=Letter}",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
+ pattern: "\\p{ =Letter}",
+ syntaxError: synErrCharPropInvalidSymbol,
+ },
+ {
+ pattern: "\\p{=}",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
+ pattern: "\\p{}",
+ syntaxError: synErrCharPropExpInvalidForm,
+ },
+ {
pattern: "(a)",
ast: newConcatNode(
newSymbolNodeWithPos(byte('a'), symPos(1)),
@@ -1031,7 +1100,9 @@ func TestParser_parse(t *testing.T) {
t.Fatal("AST is nil")
}
// printAST(os.Stdout, ast, "", "", false)
- testAST(t, tt.ast, ast)
+ if !tt.skipTestAST {
+ testAST(t, tt.ast, ast)
+ }
}
})
}