Skip to content

Commit

Permalink
Normalise the user of asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Jun 30, 2024
1 parent bddf7df commit 92a8074
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/actions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ proc deleteLevel*(map; loc: Location; um): Location =
# Do action
let action = proc (m: var Map): UndoStateData =
let sortedLevelIdx = m.sortedLevelIds.find(loc.levelId)
assert(sortedLevelIdx > -1)
assert sortedLevelIdx > -1

m.delLevel(loc.levelId)

Expand Down
4 changes: 2 additions & 2 deletions src/cmdline.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ proc parseCommandLineParams*(): tuple[configFile, mapFile: Option[string],
of "ypos", "y": winCfg.set("y-postion", parseNaturalOpt(opt, arg))
of "width", "W": winCfg.set("width", parseNaturalOpt(opt, arg))
of "height", "H": winCfg.set("height", parseNaturalOpt(opt, arg))

of "maximized", "m":
winCfg.set("maximized", parseBoolOpt(opt, arg))

Expand All @@ -105,7 +105,7 @@ proc parseCommandLineParams*(): tuple[configFile, mapFile: Option[string],
quitWithError(fmt"invalid option: {opt}")

of cmdEnd:
assert(false) # cannot happen
assert false # cannot happen

result = (configFile, mapFile, winCfg)

Expand Down
8 changes: 4 additions & 4 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ proc moveCursor(dir: CardinalDir, steps: Natural = 1; a) =
# }}}
# {{{ moveCursorDiagonal()
proc moveCursorDiagonal(dir: Direction, steps: Natural = 1; a) =
assert(dir in @[NorthWest, NorthEast, SouthWest, SouthEast])
assert dir in @[NorthWest, NorthEast, SouthWest, SouthEast]

let l = currLevel(a)

Expand Down Expand Up @@ -6057,7 +6057,7 @@ proc selectPrevLevel(a) =

var cur = a.ui.cursor
let levelIdx = map.sortedLevelIds.find(cur.levelId)
assert(levelIdx > -1)
assert levelIdx > -1

if levelIdx > 0:
cur.levelId = map.sortedLevelIds[levelIdx-1]
Expand All @@ -6070,7 +6070,7 @@ proc selectNextLevel(a) =

var cur = a.ui.cursor
let levelIdx = map.sortedLevelIds.find(cur.levelId)
assert(levelIdx > -1)
assert levelIdx > -1

if levelIdx < map.sortedLevelNames.high:
cur.levelId = map.sortedLevelIds[levelIdx+1]
Expand Down Expand Up @@ -7665,7 +7665,7 @@ proc renderLevelDropdown(a) =
mainPane = mainPaneRect(a)

var sortedLevelIdx = map.sortedLevelIds.find(cur.levelId)
assert(sortedLevelIdx > -1)
assert sortedLevelIdx > -1
let prevSortedLevelIdx = sortedLevelIdx

# Set width dynamically
Expand Down
2 changes: 1 addition & 1 deletion src/persistence.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ proc writeAppState(rw; map: Map, s: AppState) =
rw.writeBStr(s.themeName)

let currLevelIndex = map.sortedLevelIds.find(s.currLevelId)
assert(currLevelIndex > -1)
assert currLevelIndex > -1

rw.write(s.zoomLevel.uint8)
rw.write(currLevelIndex.uint16)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/hocon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ proc readNextRune(s): Rune =


proc peekRune(s; lookahead: Natural = 1): Rune =
assert(lookahead >= 1)
assert lookahead >= 1
while lookahead > s.peekBuf.len:
s.peekBuf.addLast(s.readNextRune)
s.peekBuf[lookahead-1]
Expand Down Expand Up @@ -304,7 +304,7 @@ proc readNextToken(t): Token =


proc peekToken(t; lookahead: Natural = 1): Token =
assert(lookahead >= 1)
assert lookahead >= 1
while lookahead > t.peekBuf.len:
t.peekBuf.addLast(t.readNextToken)
t.peekBuf[lookahead-1]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/rle.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ proc initRunLengthEncoder*(e; bufSize: Positive) =


proc flush*(e): bool =
assert(e.runLength <= 0x80)
assert e.runLength <= 0x80

if e.prevData > 0x7f or e.runLength > 2:
if e.bufIdx > e.buf.len-2: return false
Expand Down

0 comments on commit 92a8074

Please sign in to comment.