Skip to content

Commit 6bd181f

Browse files
bytes versions test support
1 parent 3a9170b commit 6bd181f

File tree

25 files changed

+2183
-37
lines changed

25 files changed

+2183
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ goldmaster_nocompile: build
7575
--outdir=./$(GEN_PATH)/cases \
7676
--pkgPath=github.com/vkcom/tl/$(GEN_PATH)/cases/tl \
7777
--basicPkgPath=$(BASIC_TL_PATH) \
78-
--generateByteVersions=cases_bytes \
78+
--generateByteVersions=cases_bytes. \
7979
--generateRandomCode \
8080
--generateLegacyJsonRead=false \
8181
--generateRPCCode=false \

internal/tlcodegen/test/codegen_test/casetests/json_read_test.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type mappingSuccess struct {
2727
goldenInput string
2828
// json alternatives which map to goldenInput
2929
alternatives []string
30+
// wrong json alternatives
31+
incorrectAlternatives []string
3032
}
3133

3234
type mappingTest struct {
@@ -73,6 +75,23 @@ func runMappingTest(t *testing.T, mt mappingTest) {
7375
return
7476
}
7577
}
78+
79+
for aId, alternative := range success.incorrectAlternatives {
80+
t.Run(fmt.Sprintf("Object %d - Wrong alternative %d", sId, aId), func(t *testing.T) {
81+
mt.object.FillRandom(rg)
82+
readErr := mt.object.ReadJSON(false, &basictl.JsonLexer{Data: []byte(alternative)})
83+
84+
assert.Nil(t, readErr)
85+
writeData, writeErr := mt.object.MarshalJSON()
86+
87+
assert.Nil(t, writeErr)
88+
assert.NotEqual(t, success.goldenInput, string(writeData))
89+
})
90+
91+
if t.Failed() {
92+
return
93+
}
94+
}
7695
}
7796

7897
for fId, failure := range mt.failures {
@@ -324,7 +343,7 @@ func TestDictionaryString(t *testing.T) {
324343

325344
func TestDictionaryStringStringBytes(t *testing.T) {
326345
test := mappingTest{
327-
object: &tlcases_bytes.TestDictStringString{},
346+
object: &tlcases_bytes.TestDictStringStringBytes{},
328347
successes: []mappingSuccess{
329348
{
330349
goldenInput: `{}`,
@@ -334,10 +353,13 @@ func TestDictionaryStringStringBytes(t *testing.T) {
334353
},
335354
{
336355
goldenInput: `{"dict":{"k1":"1","k2":"2"}}`,
337-
alternatives: []string{
356+
incorrectAlternatives: []string{
338357
`{"dict":{"k2":"2","k1":"1"}}`,
339358
},
340359
},
360+
{
361+
goldenInput: `{"dict":{"k1":"1","k2":"2","k3":"3","k4":"4","k5":"5","k6":"6","k7":"7","k8":"8","k9":"9"}}`,
362+
},
341363
},
342364
failures: []string{
343365
`{"dict":{"k1":"1","k2":2}}`,
@@ -349,7 +371,7 @@ func TestDictionaryStringStringBytes(t *testing.T) {
349371

350372
func TestDictionaryStringBytes(t *testing.T) {
351373
test := mappingTest{
352-
object: &tlcases_bytes.TestDictString{},
374+
object: &tlcases_bytes.TestDictStringBytes{},
353375
successes: []mappingSuccess{
354376
{
355377
goldenInput: `{}`,
@@ -359,7 +381,7 @@ func TestDictionaryStringBytes(t *testing.T) {
359381
},
360382
{
361383
goldenInput: `{"dict":{"k1":1,"k2":2}}`,
362-
alternatives: []string{
384+
incorrectAlternatives: []string{
363385
`{"dict":{"k2":2,"k1":1}}`,
364386
},
365387
},
@@ -396,7 +418,7 @@ func TestDictionaryInt(t *testing.T) {
396418

397419
func TestDictionaryIntBytes(t *testing.T) {
398420
test := mappingTest{
399-
object: &tlcases_bytes.TestDictInt{},
421+
object: &tlcases_bytes.TestDictIntBytes{},
400422
successes: []mappingSuccess{
401423
{
402424
goldenInput: `{}`,

internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTuple4String/string.go

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinTupleString/string.go

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tlcodegen/test/gen/cases/internal/tl/tlBuiltinVectorDictionaryFieldAnyIntInt/dictionaryFieldAny.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)