Enable styleCheck:usages
This commit is contained in:
parent
c5f0e2465e
commit
010aa238cf
|
@ -20,7 +20,7 @@ proc test(env, path: string) =
|
|||
if not dirExists "build":
|
||||
mkDir "build"
|
||||
exec "nim " & lang & " " & env &
|
||||
" -r --hints:off --skipParentCfg " & path
|
||||
" -r --hints:off --skipParentCfg --styleCheck:usages --styleCheck:error " & path
|
||||
|
||||
task test, "Run all tests":
|
||||
test "--threads:off", "tests/test_all"
|
||||
|
|
|
@ -132,7 +132,7 @@ proc writeIterable*(w: var JsonWriter, collection: auto) =
|
|||
|
||||
append ']'
|
||||
|
||||
proc writeArray*[T](w: var JsonWriter, elements: openarray[T]) =
|
||||
proc writeArray*[T](w: var JsonWriter, elements: openArray[T]) =
|
||||
writeIterable(w, elements)
|
||||
|
||||
# this construct catches `array[N, char]` which otherwise won't decompose into
|
||||
|
|
|
@ -10,7 +10,7 @@ template expectedToken(token: TokKind, additionalCheck = true) {.dirty.} =
|
|||
|
||||
template lexerTest(name, inputParam: string, expectations) {.dirty.} =
|
||||
test name:
|
||||
var input = dedent(inputParam)
|
||||
var input = test_dedent(inputParam)
|
||||
var stream = unsafeMemoryInput(input)
|
||||
var lexer = JsonLexer.init stream
|
||||
expectations
|
||||
|
|
|
@ -92,7 +92,7 @@ suite "toJson tests":
|
|||
check:
|
||||
s.toJson == """{"distance":20,"x":10,"y":"test"}"""
|
||||
s.toJson(typeAnnotations = true) == """{"$type":"Simple","distance":20,"x":10,"y":"test"}"""
|
||||
s.toJson(pretty = true) == dedent"""
|
||||
s.toJson(pretty = true) == test_dedent"""
|
||||
{
|
||||
"distance": 20,
|
||||
"x": 10,
|
||||
|
@ -101,7 +101,7 @@ suite "toJson tests":
|
|||
"""
|
||||
|
||||
test "handle missing fields":
|
||||
let json = dedent"""
|
||||
let json = test_dedent"""
|
||||
{
|
||||
"distance": 20,
|
||||
"y": "test"
|
||||
|
@ -116,7 +116,7 @@ suite "toJson tests":
|
|||
decoded.distance.int == 20
|
||||
|
||||
test "handle additional fields":
|
||||
let json = dedent"""
|
||||
let json = test_dedent"""
|
||||
{
|
||||
"x": -20,
|
||||
"futureObject": {"a": -1, "b": [1, 2.0, 3.1], "c": null, "d": true},
|
||||
|
@ -137,7 +137,7 @@ suite "toJson tests":
|
|||
echo "This should not have decoded ", shouldNotDecode
|
||||
|
||||
test "all fields are required and present":
|
||||
let json = dedent"""
|
||||
let json = test_dedent"""
|
||||
{
|
||||
"x": 20,
|
||||
"distance": 10,
|
||||
|
@ -153,7 +153,7 @@ suite "toJson tests":
|
|||
decoded.distance.int == 10
|
||||
|
||||
test "all fields were required, but not all were provided":
|
||||
let json = dedent"""
|
||||
let json = test_dedent"""
|
||||
{
|
||||
"x": -20,
|
||||
"distance": 10
|
||||
|
@ -165,7 +165,7 @@ suite "toJson tests":
|
|||
echo "This should not have decoded ", shouldNotDecode
|
||||
|
||||
test "all fields were required, but not all were provided (additional fields present instead)":
|
||||
let json = dedent"""
|
||||
let json = test_dedent"""
|
||||
{
|
||||
"futureBool": false,
|
||||
"y": "y value",
|
||||
|
@ -188,7 +188,7 @@ suite "toJson tests":
|
|||
echo "This should not have decoded ", shouldNotDecode
|
||||
|
||||
test "all fields are required and provided, and additional ones are present":
|
||||
let json = dedent"""
|
||||
let json = test_dedent"""
|
||||
{
|
||||
"x": 20,
|
||||
"distance": 10,
|
||||
|
@ -219,7 +219,7 @@ suite "toJson tests":
|
|||
var x = HoldsArray(data: @[1, 2, 3, 4])
|
||||
|
||||
check:
|
||||
x.toJson(pretty = true) == dedent"""
|
||||
x.toJson(pretty = true) == test_dedent"""
|
||||
{
|
||||
"data": [
|
||||
1,
|
||||
|
@ -243,7 +243,7 @@ suite "toJson tests":
|
|||
test "Unusual field names":
|
||||
let r = HasUnusualFieldNames(`type`: "uint8", renamedField: "field")
|
||||
check:
|
||||
r.toJSON == """{"type":"uint8","renamed":"field"}"""
|
||||
r.toJson == """{"type":"uint8","renamed":"field"}"""
|
||||
r == Json.decode("""{"type":"uint8", "renamed":"field"}""", HasUnusualFieldNames)
|
||||
|
||||
test "Option types":
|
||||
|
@ -280,7 +280,7 @@ suite "toJson tests":
|
|||
|
||||
proc testJsonHolders(HasJsonData: type) =
|
||||
let
|
||||
data1 = dedent"""
|
||||
data1 = test_dedent"""
|
||||
{
|
||||
"name": "Data 1",
|
||||
"data": [1, 2, 3, 4],
|
||||
|
@ -288,7 +288,7 @@ suite "toJson tests":
|
|||
}
|
||||
"""
|
||||
let
|
||||
data2 = dedent"""
|
||||
data2 = test_dedent"""
|
||||
{
|
||||
"name": "Data 2",
|
||||
"data": "some string",
|
||||
|
@ -296,7 +296,7 @@ suite "toJson tests":
|
|||
}
|
||||
"""
|
||||
let
|
||||
data3 = dedent"""
|
||||
data3 = test_dedent"""
|
||||
{
|
||||
"name": "Data 3",
|
||||
"data": {"field1": 10, "field2": [1, 2, 3], "field3": "test"},
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import
|
||||
strutils
|
||||
|
||||
proc dedent*(s: string): string =
|
||||
# `dedent` exists in newer nim version
|
||||
# and doesn't behave the same
|
||||
proc test_dedent*(s: string): string =
|
||||
var s = s.strip(leading = false)
|
||||
var minIndent = high(int)
|
||||
for l in s.splitLines:
|
||||
|
|
Loading…
Reference in New Issue