48 lines
896 B
Go
48 lines
896 B
Go
package lang
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseServerDefinitions(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want AST
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "simple server definition",
|
|
input: `server MyApp host "localhost" port 8080`,
|
|
want: AST{
|
|
Definitions: []Definition{
|
|
{
|
|
Server: &Server{
|
|
Name: "MyApp",
|
|
Settings: []ServerSetting{
|
|
{Host: stringPtr("localhost")},
|
|
{Port: intPtr(8080)},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := ParseInput(tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ParseInput() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
|
|
if !tt.wantErr && !astEqual(got, tt.want) {
|
|
t.Errorf("ParseInput() mismatch.\nGot: %+v\nWant: %+v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|