From 0188cd49fe3b5797382bedb2fea767171090ad1f Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 4 Oct 2021 11:30:24 +0200 Subject: Cosmetics --- src/field.nim | 16 ++++++++-------- tests/field.nim | 46 ++++++++++++++++++++++++---------------------- tests/stack.nim | 2 +- 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..= 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 -- cgit v1.2.3