Skip to content

Commit 586b86b

Browse files
committed
Improve coverage
1 parent 51a8a74 commit 586b86b

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

checker/checker_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,31 @@ func TestCheck_PointerNode(t *testing.T) {
703703
assert.Error(t, err)
704704
assert.Contains(t, err.Error(), "cannot use pointer accessor outside closure")
705705
}
706+
707+
func TestCheck_TypeWeights(t *testing.T) {
708+
types := map[string]interface{}{
709+
"Uint": uint(1),
710+
"Uint8": uint8(2),
711+
"Uint16": uint16(3),
712+
"Uint32": uint32(4),
713+
"Uint64": uint64(5),
714+
"Int": int(6),
715+
"Int8": int8(7),
716+
"Int16": int16(8),
717+
"Int32": int32(9),
718+
"Int64": int64(10),
719+
"Float32": float32(11),
720+
"Float64": float64(12),
721+
}
722+
for a := range types {
723+
for b := range types {
724+
tree, err := parser.Parse(fmt.Sprintf("%s + %s", a, b))
725+
require.NoError(t, err)
726+
727+
config := conf.New(types)
728+
729+
_, err = checker.Check(tree, config)
730+
require.NoError(t, err)
731+
}
732+
}
733+
}

file/source.go

-19
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,3 @@ func (s *Source) findLineOffset(line int) (int32, bool) {
7474
}
7575
return -1, false
7676
}
77-
78-
// findLine finds the line that contains the given character offset and
79-
// returns the line number and offset of the beginning of that line.
80-
// Note that the last line is treated as if it contains all offsets
81-
// beyond the end of the actual source.
82-
func (s *Source) findLine(characterOffset int32) (int32, int32) {
83-
var line int32 = 1
84-
for _, lineOffset := range s.lineOffsets {
85-
if lineOffset > characterOffset {
86-
break
87-
} else {
88-
line++
89-
}
90-
}
91-
if line == 1 {
92-
return line, 0
93-
}
94-
return line, s.lineOffsets[line-2]
95-
}

file/source_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package file
22

33
import (
4+
"encoding/json"
5+
"github.com/stretchr/testify/assert"
46
"testing"
57
)
68

@@ -52,3 +54,15 @@ func TestStringSource_SnippetSingleLine(t *testing.T) {
5254
t.Errorf(unexpectedSnippet, t.Name(), str2, "")
5355
}
5456
}
57+
58+
func TestStringSource_MarshalJSON(t *testing.T) {
59+
source := NewSource("hello, world")
60+
encoded, err := json.Marshal(source)
61+
assert.NoError(t, err)
62+
assert.Equal(t, `[104,101,108,108,111,44,32,119,111,114,108,100]`, string(encoded))
63+
64+
decoded := &Source{}
65+
err = json.Unmarshal(encoded, decoded)
66+
assert.NoError(t, err)
67+
assert.Equal(t, source.Content(), decoded.Content())
68+
}

0 commit comments

Comments
 (0)