From cb9d92f0b4e0097579f6e5da1dc6e2f063b532a9 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sun, 28 Nov 2021 00:37:03 +0900 Subject: Make contributory properties unavailable except internal use This change follows [UAX #44 5.13 Property APIs]. > The following subtypes of Unicode character properties should generally not be exposed in APIs, > except in limited circumstances. They may not be useful, particularly in public API collections, > and may instead prove misleading to the users of such API collections. > > * Contributory properties are not recommended for public APIs. > ... https://unicode.org/reports/tr44/#Property_APIs --- compiler/parser_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'compiler/parser_test.go') diff --git a/compiler/parser_test.go b/compiler/parser_test.go index 7c33fb4..e4a6fe2 100644 --- a/compiler/parser_test.go +++ b/compiler/parser_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/nihei9/maleeni/spec" + "github.com/nihei9/maleeni/ucd" ) func symPos(n uint16) symbolPosition { @@ -1241,6 +1242,37 @@ func TestParse(t *testing.T) { } } +func TestParse_ContributoryPropertyIsNotExposed(t *testing.T) { + for _, cProp := range ucd.ContributoryProperties() { + t.Run(fmt.Sprintf("%v", cProp), func(t *testing.T) { + ast, _, err := parse([]*patternEntry{ + { + id: spec.LexModeKindIDMin, + pattern: []byte(fmt.Sprintf(`\p{%v=yes}`, cProp)), + }, + }, nil) + if err == nil { + t.Fatalf("expected syntax error; got: nil") + } + parseErrs, ok := err.(*ParseErrors) + if !ok { + t.Fatalf("expected ParseErrors; got: %v (type: %T)", err, err) + } + parseErr := parseErrs.Errors[0].Cause + synErr, ok := parseErr.(*SyntaxError) + if !ok { + t.Fatalf("expected SyntaxError; got: %v (type: %T)", parseErr, parseErr) + } + if synErr != synErrCharPropUnsupported { + t.Fatalf("unexpected syntax error; want: %v, got: %v", synErrCharPropUnsupported, synErr) + } + if ast != nil { + t.Fatalf("ast is not nil") + } + }) + } +} + func TestParse_FollowAndSymbolTable(t *testing.T) { root, symTab, err := parse([]*patternEntry{ { -- cgit v1.2.3