Improve coverage

This commit is contained in:
Anton Medvedev
2022-10-09 10:58:13 +02:00
parent 611623d756
commit ab3541c0ef
3 changed files with 42 additions and 19 deletions
+28
View File
@@ -703,3 +703,31 @@ func TestCheck_PointerNode(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "cannot use pointer accessor outside closure")
}
func TestCheck_TypeWeights(t *testing.T) {
types := map[string]interface{}{
"Uint": uint(1),
"Uint8": uint8(2),
"Uint16": uint16(3),
"Uint32": uint32(4),
"Uint64": uint64(5),
"Int": int(6),
"Int8": int8(7),
"Int16": int16(8),
"Int32": int32(9),
"Int64": int64(10),
"Float32": float32(11),
"Float64": float64(12),
}
for a := range types {
for b := range types {
tree, err := parser.Parse(fmt.Sprintf("%s + %s", a, b))
require.NoError(t, err)
config := conf.New(types)
_, err = checker.Check(tree, config)
require.NoError(t, err)
}
}
}
-19
View File
@@ -74,22 +74,3 @@ func (s *Source) findLineOffset(line int) (int32, bool) {
}
return -1, false
}
// findLine finds the line that contains the given character offset and
// returns the line number and offset of the beginning of that line.
// Note that the last line is treated as if it contains all offsets
// beyond the end of the actual source.
func (s *Source) findLine(characterOffset int32) (int32, int32) {
var line int32 = 1
for _, lineOffset := range s.lineOffsets {
if lineOffset > characterOffset {
break
} else {
line++
}
}
if line == 1 {
return line, 0
}
return line, s.lineOffsets[line-2]
}
+14
View File
@@ -1,6 +1,8 @@
package file
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)
@@ -52,3 +54,15 @@ func TestStringSource_SnippetSingleLine(t *testing.T) {
t.Errorf(unexpectedSnippet, t.Name(), str2, "")
}
}
func TestStringSource_MarshalJSON(t *testing.T) {
source := NewSource("hello, world")
encoded, err := json.Marshal(source)
assert.NoError(t, err)
assert.Equal(t, `[104,101,108,108,111,44,32,119,111,114,108,100]`, string(encoded))
decoded := &Source{}
err = json.Unmarshal(encoded, decoded)
assert.NoError(t, err)
assert.Equal(t, source.Content(), decoded.Content())
}