go-typst/identifier_test.go
David Vogel 755cee77ac Several changes
- Make VariableEncoder write* methods private
- Add VariableEncoder method to write correctly escaped string literals
- Fix error handling in VariableEncoder
- Add support for time.Time and time.Duration
- Fix MarshalText usage in VariableEncoder
- Encode byte slice so that it is a valid typst bytes object
- Extend tests
- Add functions to clean and check typst identifiers
- Split Error into Error and ErrorWithPath
- Add CLIOptions
2024-12-18 17:25:28 +01:00

50 lines
894 B
Go

package typst
import (
"testing"
)
func TestCleanIdentifier(t *testing.T) {
tests := []struct {
input string
want string
}{
{"", "_invalid_"},
{"_", "_invalid_"},
{"_-", "_-"},
{"-foo-", "_foo-"},
{"foo", "foo"},
{"😊", "_invalid_"},
{"foo😊", "foo_"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
if got := CleanIdentifier(tt.input); got != tt.want {
t.Errorf("IsIdentifier() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsIdentifier(t *testing.T) {
tests := []struct {
input string
want bool
}{
{"", false},
{"_", false},
{"_-", true},
{"-foo", false},
{"foo", true},
{"😊", false},
{"_😊", false},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
if got := IsIdentifier(tt.input); got != tt.want {
t.Errorf("IsIdentifier() = %v, want %v", got, tt.want)
}
})
}
}