| 1 | package token_testscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "testingscip-go gomod github.com/golang/go/src go1.21.0 testing/" |
| 5 | |
| 6 | "github.com/goccy/go-yaml/tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/" |
| 7 | ) |
| 8 | |
| 9 | func TestTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token_test`/TestToken().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) { |
| 10 | pos := &tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#{} |
| 11 | tokens := tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#{ |
| 12 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.SequenceEntryscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/SequenceEntry().("-", pos), |
| 13 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.MappingKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/MappingKey().(pos), |
| 14 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.MappingValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/MappingValue().(pos), |
| 15 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.CollectEntryscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/CollectEntry().(",", pos), |
| 16 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.SequenceStartscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/SequenceStart().("[", pos), |
| 17 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.SequenceEndscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/SequenceEnd().("]", pos), |
| 18 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.MappingStartscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/MappingStart().("{", pos), |
| 19 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.MappingEndscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/MappingEnd().("}", pos), |
| 20 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Comment().("#", "#", pos), |
| 21 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Anchor().("&", pos), |
| 22 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Aliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Alias().("*", pos), |
| 23 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Literalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Literal().("|", "|", pos), |
| 24 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Foldedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Folded().(">", ">", pos), |
| 25 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.SingleQuotescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/SingleQuote().("'", "'", pos), |
| 26 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.DoubleQuotescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/DoubleQuote().(`"`, `"`, pos), |
| 27 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Directivescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Directive().("%", pos), |
| 28 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Spacescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Space().(pos), |
| 29 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.MergeKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/MergeKey().("<<", pos), |
| 30 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.DocumentHeaderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/DocumentHeader().("---", pos), |
| 31 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.DocumentEndscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/DocumentEnd().("...", pos), |
| 32 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("1", "1", pos), |
| 33 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("3.14", "3.14", pos), |
| 34 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("-0b101010", "-0b101010", pos), |
| 35 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("0xA", "0xA", pos), |
| 36 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("685.230_15e+03", "685.230_15e+03", pos), |
| 37 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("02472256", "02472256", pos), |
| 38 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("0o2472256", "0o2472256", pos), |
| 39 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("", "", pos), |
| 40 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("_1", "_1", pos), |
| 41 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("1.1.1.1", "1.1.1.1", pos), |
| 42 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("+", "+", pos), |
| 43 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("-", "-", pos), |
| 44 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("_", "_", pos), |
| 45 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("~", "~", pos), |
| 46 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("true", "true", pos), |
| 47 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("false", "false", pos), |
| 48 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().(".nan", ".nan", pos), |
| 49 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().(".inf", ".inf", pos), |
| 50 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("-.inf", "-.inf", pos), |
| 51 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("null", "null", pos), |
| 52 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!null", "!!null", pos), |
| 53 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!map", "!!map", pos), |
| 54 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!str", "!!str", pos), |
| 55 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!seq", "!!seq", pos), |
| 56 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!binary", "!!binary", pos), |
| 57 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!omap", "!!omap", pos), |
| 58 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!set", "!!set", pos), |
| 59 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!int", "!!int", pos), |
| 60 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!!float", "!!float", pos), |
| 61 | tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tagscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tag().("!hoge", "!hoge", pos), |
| 62 | } |
| 63 | tokens.Dumpscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#Dump().() |
| 64 | tokens.Addscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#Add().(tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/New().("hoge", "hoge", pos)) |
| 65 | if tokens[len(tokens)-1].PreviousTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#PreviousType().() != tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.TagTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/TagType. { |
| 66 | t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("invalid previous token type") |
| 67 | } |
| 68 | if tokens[0].PreviousTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#PreviousType().() != tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.UnknownTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/UnknownType. { |
| 69 | t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("invalid previous token type") |
| 70 | } |
| 71 | if tokens[len(tokens)-2].NextTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#NextType().() != tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.StringTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/StringType. { |
| 72 | t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("invalid next token type") |
| 73 | } |
| 74 | if tokens[len(tokens)-1].NextTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#NextType().() != tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.UnknownTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/UnknownType. { |
| 75 | t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("invalid next token type") |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestIsNeedQuotedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token_test`/TestIsNeedQuoted().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) { |
| 80 | needQuotedTests := []string{ |
| 81 | "", |
| 82 | "true", |
| 83 | "1.234", |
| 84 | "0b11111111111111111111111111111111111111111111111111111111111111111", |
| 85 | "0o7777777777777777777777777777777777777777", |
| 86 | "999999999999999999999999999999999999999999", |
| 87 | "0xffffffffffffffffffffffffffffffffffffffff", |
| 88 | "1:1", |
| 89 | "2001-12-15T02:59:43.1Z", |
| 90 | "2001-12-14t21:59:43.10-05:00", |
| 91 | "2001-12-15 2:59:43.10", |
| 92 | "2002-12-14", |
| 93 | "hoge # comment", |
| 94 | "\\0", |
| 95 | "#a b", |
| 96 | "*a b", |
| 97 | "&a b", |
| 98 | "{a b", |
| 99 | "}a b", |
| 100 | "[a b", |
| 101 | "]a b", |
| 102 | ",a b", |
| 103 | "!a b", |
| 104 | "|a b", |
| 105 | ">a b", |
| 106 | ">a b", |
| 107 | "%a b", |
| 108 | `'a b`, |
| 109 | `"a b`, |
| 110 | "a:", |
| 111 | "a: b", |
| 112 | "y", |
| 113 | "Y", |
| 114 | "yes", |
| 115 | "Yes", |
| 116 | "YES", |
| 117 | "n", |
| 118 | "N", |
| 119 | "no", |
| 120 | "No", |
| 121 | "NO", |
| 122 | "on", |
| 123 | "On", |
| 124 | "ON", |
| 125 | "off", |
| 126 | "Off", |
| 127 | "OFF", |
| 128 | "@test", |
| 129 | " a", |
| 130 | " a ", |
| 131 | "a ", |
| 132 | "null", |
| 133 | "Null", |
| 134 | "NULL", |
| 135 | "~", |
| 136 | "-", |
| 137 | "- --foo", |
| 138 | } |
| 139 | for i, test := range needQuotedTests { |
| 140 | if !tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.IsNeedQuotedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/IsNeedQuoted().(test) { |
| 141 | t.Errorfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Errorf().("%d: failed to quoted judge for %s", i, test) |
| 142 | } |
| 143 | } |
| 144 | notNeedQuotedTests := []string{ |
| 145 | "Hello World", |
| 146 | // time.Parse cannot handle: "2001-12-14 21:59:43.10 -5" from the examples. |
| 147 | // https://yaml.org/type/timestamp.html |
| 148 | "2001-12-14 21:59:43.10 -5", |
| 149 | } |
| 150 | for i, test := range notNeedQuotedTests { |
| 151 | if tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.IsNeedQuotedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/IsNeedQuoted().(test) { |
| 152 | t.Errorfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Errorf().("%d: failed to quoted judge for %s", i, test) |
| 153 | } |
| 154 | } |
| 155 | } |