mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-01 23:21:59 +01:00
words -> str. test roundtrip
This commit is contained in:
parent
06724528cc
commit
b9fd4df60f
@ -18,6 +18,11 @@ func testParse(t *testing.T, s string) {
|
||||
fmt.Printf("%s\n", s)
|
||||
dumpWords(words, " ")
|
||||
fmt.Printf("\n")
|
||||
|
||||
outStr := wordsToStr(words)
|
||||
if outStr != s {
|
||||
t.Errorf("tokenization output does not match input: %q => %q", s, outStr)
|
||||
}
|
||||
}
|
||||
|
||||
func Test1(t *testing.T) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package shparse
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@ -108,3 +109,14 @@ func Tokenize(cmd string) []*wordType {
|
||||
state.finish(c)
|
||||
return state.Rtn
|
||||
}
|
||||
|
||||
func wordsToStr(words []*wordType) string {
|
||||
var buf bytes.Buffer
|
||||
for _, word := range words {
|
||||
if len(word.Prefix) > 0 {
|
||||
buf.WriteString(string(word.Prefix))
|
||||
}
|
||||
buf.WriteString(string(word.Raw))
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user