package main
import (
"errors"
"strings"
"testing"
)
func TestScanSingleConfigToken(t *testing.T) {
var singleTokenTests = []struct {
input string
expectedToken ConfigToken
}{
{
input: "-!\"word1世界",
expectedToken: ConfigToken{
tokenType: CtkWord,
value: "-!\"word1世界",
rawValue: "-!\"word1世界",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 10,
},
},
},
{
input: "\"word \\t\\\"with\\\"\\n spaces\"",
expectedToken: ConfigToken{
tokenType: CtkWord,
value: "word \t\"with\"\n spaces",
rawValue: "\"word \\t\\\"with\\\"\\n spaces\"",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 26,
},
},
},
{
input: " \t\r\v\f",
expectedToken: ConfigToken{
tokenType: CtkWhiteSpace,
value: " \t\r\v\f",
rawValue: " \t\r\v\f",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 5,
},
},
},
{
input: "# Comment",
expectedToken: ConfigToken{
tokenType: CtkComment,
value: "# Comment",
rawValue: "# Comment",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 9,
},
},
},
{
input: "--option",
expectedToken: ConfigToken{
tokenType: CtkOption,
value: "--option",
rawValue: "--option",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 8,
},
},
},
{
input: "!git status",
expectedToken: ConfigToken{
tokenType: CtkShellCommand,
value: "!git status",
rawValue: "!git status",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 11,
},
},
},
{
input: "@git status",
expectedToken: ConfigToken{
tokenType: CtkShellCommand,
value: "@git status",
rawValue: "@git status",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 11,
},
},
},
{
input: "\n",
expectedToken: ConfigToken{
tokenType: CtkTerminator,
value: "\n",
rawValue: "\n",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 1,
},
},
},
{
input: "",
expectedToken: ConfigToken{
tokenType: CtkEOF,
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 1,
},
},
},
{
input: "\"Unterminated string",
expectedToken: ConfigToken{
tokenType: CtkInvalid,
value: "\"Unterminated string",
rawValue: "\"Unterminated string",
startPos: ConfigScannerPos{
line: 1,
col: 1,
},
endPos: ConfigScannerPos{
line: 1,
col: 20,
},
err: errors.New("Unterminated string"),
},
},
}
<