mirror of
https://github.com/Dadido3/go-typst.git
synced 2025-04-11 12:13:16 +00:00
- 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
50 lines
894 B
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|