aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-10-04 11:30:24 +0200
committerJulien Dessaux2021-10-04 11:30:24 +0200
commit0188cd49fe3b5797382bedb2fea767171090ad1f (patch)
tree0eda71cbf4cd9bd7f9b8b3aa12d9783dfb48c30e
parentImproved stack.nim test coverage (diff)
downloadnimfunge98-0188cd49fe3b5797382bedb2fea767171090ad1f.tar.gz
nimfunge98-0188cd49fe3b5797382bedb2fea767171090ad1f.tar.bz2
nimfunge98-0188cd49fe3b5797382bedb2fea767171090ad1f.zip
Cosmetics
-rw-r--r--src/field.nim16
-rw-r--r--tests/field.nim46
-rw-r--r--tests/stack.nim2
3 files changed, 33 insertions, 31 deletions
diff --git a/src/field.nim b/src/field.nim
index e7280f8..8d609f7 100644
--- a/src/field.nim
+++ b/src/field.nim
@@ -12,13 +12,13 @@ func Blank*(f: var Field, x, y: int) =
if y < f.y or y >= f.y+f.ly: # outside the field
return
var l = addr f.lines[y-f.y]
- if x < l.x or x >= l.x+l.l: # outside the field
+ if x < l.x or x >= l.x+l.l: # outside the field
return
- if x > l.x and x < l.x+l.l-1: # just set the value
+ if x > l.x and x < l.x+l.l-1: # just set the value
l.columns[x-l.x] = int(' ')
return
if l.l == 1: # this was the last character on the line
- if y == f.y: # we need to trim the leading lines
+ if y == f.y: # we need to trim the leading lines
var i = 1
while f.lines[i].l == 0:
inc i
@@ -34,14 +34,14 @@ func Blank*(f: var Field, x, y: int) =
else: # it was a line in the middle
l.l = 0
l.columns = @[]
- elif x == l.x: # we need to remove leading spaces
+ elif x == l.x: # we need to remove leading spaces
var i = 1
while l.columns[i] == int(' '):
inc i
l.x += i
l.columns = l.columns[i..<l.l]
l.l -= i
- elif x == l.l+l.x-1: # we need to remove trailing spaces
+ elif x == l.l+l.x-1: # we need to remove trailing spaces
var i = l.l-2
while l.columns[i] == int(' '):
dec i
@@ -77,7 +77,7 @@ proc Load*(f: var Field, filename: string): bool =
f.lines.add(Line())
var l = addr f.lines[0]
var trailingSpaces = 0
- var data: array[255,char]
+ var data: array[255, char]
while true:
let n = file.readChars(data, 0, 255)
if n <= 0:
@@ -136,9 +136,9 @@ func Set*(f: var Field, x, y, v: int) =
if v == int(' '):
f.Blank(x, y)
elif y >= f.y:
- if y < f.y+f.ly: # the line exists
+ if y < f.y+f.ly: # the line exists
var l = addr f.lines[y-f.y]
- if l.l == 0: # An empty line is a special case
+ if l.l == 0: # An empty line is a special case
l.x = x
l.l = 1
l.columns = @[v]
diff --git a/tests/field.nim b/tests/field.nim
index 8acd6b3..e000016 100644
--- a/tests/field.nim
+++ b/tests/field.nim
@@ -92,14 +92,14 @@ suite "Field":
f.Blank(5, 2)
check f == moinsd
const moinsl = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])])
- f.Blank(-2,0)
+ f.Blank(-2, 0)
check f == moinsl
const moinsr = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @[int('@')])])
- f.Blank(4,0)
+ f.Blank(4, 0)
check f == moinsr
test "Get":
- check minimal.Get(0,0) == int('@')
- check minimal.Get(1,0) == int(' ')
+ check minimal.Get(0, 0) == int('@')
+ check minimal.Get(1, 0) == int(' ')
test "IsIn":
check minimal.IsIn(0, 0) == true
check minimal.IsIn(1, 0) == false
@@ -113,41 +113,43 @@ suite "Field":
var min: Field
check min.Load("examples/minimal.b98") == true
check min == minimal
- var hello1A: Field; var hello1B = Field(lx: 24, ly: 1, lines: @[Line(l:24, columns: @['6', '4', '+', '"', '!', 'd', 'l', 'r', 'o', 'W', ' ', ',', 'o', 'l', 'l', 'e', 'H', '"', '>', ':', '#', ',', '_', '@'].cols)])
+ var hello1A: Field; var hello1B = Field(lx: 24, ly: 1, lines: @[Line(l: 24, columns: @['6', '4', '+', '"', '!', 'd', 'l', 'r', 'o', 'W', ' ', ',', 'o', 'l', 'l', 'e', 'H', '"',
+ '>', ':', '#', ',', '_', '@'].cols)])
check hello1A.Load("examples/hello.b98") == true
check hello1A == hello1B
var rn: Field
check rn.Load("examples/rn.b98") == true
check rn == hello1B
- var hello2A: Field; var hello2B = Field(x: 1, lx: 33, ly: 2,lines: @[
- Line(x:33, l:1, columns: @['v'].cols),
- Line(x:1, l:33, columns: @['@', ' ', '>', ' ', '#', ';', '>', ':', '#', ',', '_', 'e', '-', 'j', ';', ' ', '"', 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', 'd', 'a', '<'].cols)
+ var hello2A: Field; var hello2B = Field(x: 1, lx: 33, ly: 2, lines: @[
+ Line(x: 33, l: 1, columns: @['v'].cols),
+ Line(x: 1, l: 33, columns: @['@', ' ', '>', ' ', '#', ';', '>', ':', '#', ',', '_', 'e', '-', 'j', ';', ' ', '"', 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
+ '"', 'd', 'a', '<'].cols)
])
check hello2A.Load("examples/hello2.b98") == true
check hello2A == hello2B
- var factorial2A: Field; var factorial2B = Field(x: 0, lx: 15, ly: 2,lines: @[
- Line(x:0, l:15, columns: @['&', '>', ':', '1', '-', ':', 'v', ' ', 'v', ' ', '*', '_', '$', '.', '@'].cols),
- Line(x:1, l:11, columns: @['^', ' ', ' ', ' ', ' ', '_', '$', '>', '\\', ':', '^'].cols)
+ var factorial2A: Field; var factorial2B = Field(x: 0, lx: 15, ly: 2, lines: @[
+ Line(x: 0, l: 15, columns: @['&', '>', ':', '1', '-', ':', 'v', ' ', 'v', ' ', '*', '_', '$', '.', '@'].cols),
+ Line(x: 1, l: 11, columns: @['^', ' ', ' ', ' ', ' ', '_', '$', '>', '\\', ':', '^'].cols)
])
check factorial2A.Load("examples/factorial.b98") == true
check factorial2A == factorial2B
- var dna2A: Field; var dna2B = Field(x: 0, lx: 7, ly: 8,lines: @[
- Line(x:0, l:7, columns: @['7', '^', 'D', 'N', '>', 'v', 'A'].cols),
- Line(x:0, l:7, columns: @['v', '_', '#', 'v', '?', ' ', 'v'].cols),
- Line(x:0, l:7, columns: @['7', '^', '<', '"', '"', '"', '"'].cols),
- Line(x:0, l:7, columns: @['3', ' ', ' ', 'A', 'C', 'G', 'T'].cols),
- Line(x:0, l:7, columns: @['9', '0', '!', '"', '"', '"', '"'].cols),
- Line(x:0, l:7, columns: @['4', '*', ':', '>', '>', '>', 'v'].cols),
- Line(x:0, l:7, columns: @['+', '8', '^', '-', '1', ',', '<'].cols),
- Line(x:0, l:7, columns: @['>', ' ', ',', '+', ',', '@', ')'].cols),
+ var dna2A: Field; var dna2B = Field(x: 0, lx: 7, ly: 8, lines: @[
+ Line(x: 0, l: 7, columns: @['7', '^', 'D', 'N', '>', 'v', 'A'].cols),
+ Line(x: 0, l: 7, columns: @['v', '_', '#', 'v', '?', ' ', 'v'].cols),
+ Line(x: 0, l: 7, columns: @['7', '^', '<', '"', '"', '"', '"'].cols),
+ Line(x: 0, l: 7, columns: @['3', ' ', ' ', 'A', 'C', 'G', 'T'].cols),
+ Line(x: 0, l: 7, columns: @['9', '0', '!', '"', '"', '"', '"'].cols),
+ Line(x: 0, l: 7, columns: @['4', '*', ':', '>', '>', '>', 'v'].cols),
+ Line(x: 0, l: 7, columns: @['+', '8', '^', '-', '1', ',', '<'].cols),
+ Line(x: 0, l: 7, columns: @['>', ' ', ',', '+', ',', '@', ')'].cols),
])
check dna2A.Load("examples/dna.b98") == true
check dna2A == dna2B
test "Set":
var f = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @['>'].cols)])
- f.Set(0,0,int('@'))
+ f.Set(0, 0, int('@'))
check f == minimal
- f.Set(1,0,int(' '))
+ f.Set(1, 0, int(' '))
check f == minimal
const xappend = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])])
f.Set(4, 0, int('r'))
diff --git a/tests/stack.nim b/tests/stack.nim
index 623fb1c..0f7e4c8 100644
--- a/tests/stack.nim
+++ b/tests/stack.nim
@@ -133,5 +133,5 @@ suite "Stack":
test "Next":
var empty = NewStack()
check empty[].Next() == nil
- var some = NewStack(next=empty)
+ var some = NewStack(next = empty)
check some[].Next() == empty