Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue error when array max_count is not an int. #22

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion array.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ func (self *ArrayParser) New(profile *Profile, options *ordereddict.Dict) (Parse

// Default to 0 length
result.options.Count, _ = options.GetInt64("count")
result.options.MaxCount, _ = options.GetInt64("max_count")
max_count_any, pres := options.Get("max_count")
if pres {
result.options.MaxCount, pres = to_int64(max_count_any)
if !pres {
return nil, fmt.Errorf("Array max_count must be an int not %T", max_count_any)
}
}

if result.options.MaxCount == 0 {
result.options.MaxCount = 1000
Expand Down
23 changes: 23 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ func TestStructParser(t *testing.T) {
goldie.Assert(t, "TestStructParser", serialized)
}

func TestArrayParserError(t *testing.T) {
profile := NewProfile()
AddModel(profile)

scope := MakeScope()
scope.SetLogger(log.New(os.Stderr, " ", 0))

definition := `
[
["TestStruct", 0, [
["Field1", 2, "Array", {
"max_count": "x=>x.Length",
"type": "uint8"
}],
]
]]
`
err := profile.ParseStructDefinitions(definition)
assert.Error(t, err)

assert.Contains(t, err.Error(), "Array max_count must be an int not string")
}

func TestArrayParser(t *testing.T) {
profile := NewProfile()
AddModel(profile)
Expand Down
Loading