summary refs log tree commit diff stats
path: root/tests/range
Commit message (Collapse)AuthorAgeFilesLines
* fix #19678 Broken behavior with string ranges in case labels (#20475)Bung2022-10-011-0/+17
| | | | | | | | | * fix #19678 Broken behavior with string ranges in case labels * Update compiler/semtypes.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* moderate system cleanup & refactor (#20355)metagn2022-09-281-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * system refactor, move out 600 lines * compilation, slice, backwardsindex, misc_num moved out of system * some procs/types moved into arithmetics, basic_types * system no longer depends on syncio * some procs moved around to fit with their surroundings * make exceptions an import, old ops to misc_num * move instantiationInfo back * move back nim version, fix windows echo * include compilation * better docs for imported modules, fix unsigned ops also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem * fix terminal * workaround IC test & weird csize bug, changelog * move NimMajor etc back to compilation, rebase for CI * try ic fix * form single `indices`, slim out TaintedString, try fix IC * fix CI, update changelog, addQuitProc * fix CI * try fix CI * actually fix CI finally hopefully * Update lib/system/compilation.nim Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> * update kochdocs * hopefully fix csize uses for slimsystem * fix tquit Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* change `--hint[X] => --hint:X` in nim repo (avoids shell quoting issues) ↵Timothee Cour2021-05-261-1/+1
| | | | (#18085)
* fix range to unsigned conversion (#17754)Tanguy Cizain2021-04-171-0/+12
|
* Error -> Defect for defects (#13908)Jacek Sieka2020-04-282-2/+2
| | | | | | | | | | | | | | * Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
* catchable defects (#13626)Andreas Rumpf2020-03-122-2/+2
| | | | | | | | | | * allow defects to be caught even for --exceptions:goto (WIP) * implemented the new --panics:on|off switch; refs https://github.com/nim-lang/RFCs/issues/180 * new implementation for integer overflow checking * produce a warning if a user-defined exception type inherits from Exception directly * applied Timothee's suggestions; improved the documentation and replace the term 'checked runtime check' by 'panic' * fixes #13627 * don't inherit from Exception directly
* fix range[enum] type conversion (#13204) [backport]Jasper Jenkins2020-01-201-0/+33
|
* Merge branch 'devel' into uint-range-checksAndreas Rumpf2019-09-021-0/+6
|\
| * weaking unsigned/signed indexing requirements in order to not break too much ↵Araq2019-09-021-0/+6
| | | | | | | | existing code
* | make test greenAraq2019-09-021-38/+48
| |
* | Merge branch 'devel' into uint-range-checksAraq2019-09-021-0/+18
|\|
| * Fix int literals and range interaction (#11197)Oscar Nihlgård2019-08-311-2/+9
| | | | | | | | | | | | | | | | * Fix int literals and range interaction * Fix test * remove float range fix; update changelog
| * Fix several float range issuesOscar Nihlgård2019-08-271-0/+11
| |
* | renamed and moved testAraq2019-09-021-0/+42
|/
* Tighten the conversion from tyRange to scalar types (#10495)LemonBoy2019-02-231-0/+13
| | | | | | | | | * Tighten the conversion from tyRange to scalar types. Introduce the `isIntConv` rule for unsigned types. Do not allow mixed-signedness conversions between ranges and scalar types. * More json adjustments
* require errormsg to be specified before file.Arne Döring2018-12-113-5/+1
|
* Merge tests into a larger file (part 5 of ∞) (#9368)Miran2018-10-165-112/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * merge magics * merge metatype tests * merge method tests * merge objects tests * change `import future` to `import sugar` Nim in Action tests are left with `import future`, to ensure compatibility. * merge overload tests * merge proc tests * merge procvar tests * merge range tests * merge seq tests * merge sets tests * remove wrong assert from `tsets3` * fix `jsTests` * better fix
* make tests green againAndreas Rumpf2018-05-021-1/+1
|
* Fix typo in new testDaniil Yarancev2017-11-011-1/+1
|
* make range type checking more restrictive, see tn8vsint16 test case; minor ↵Andreas Rumpf2017-11-011-0/+18
| | | | breaking change
* Remove expr/stmt (#5857)Arne Döring2017-07-251-3/+2
|
* tests: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-046-28/+28
| | | | via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
* made some tests greenAraq2014-08-312-3/+2
|
* made some tests greenAraq2014-08-131-2/+2
|
* Changed tests and tools to use 'discard' statements instead of 'nil' for ↵Clay Sweetser2014-02-152-2/+2
| | | | empty blocks.
* new tester; all tests categorizedAraq2014-01-137-0/+157
#dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# A doubly linked list permits bidirectional traversal.

container duplex-list:_elem [
  value:_elem
  next:address:duplex-list:_elem
  prev:address:duplex-list:_elem
]

# should I say in/contained-in:result, allow ingredients to refer to products?
def push x:_elem, in:address:duplex-list:_elem -> in:address:duplex-list:_elem [
  local-scope
  load-ingredients
  result:address:duplex-list:_elem <- new {(duplex-list _elem): type}
  *result <- merge x, in, 0
  {
    break-unless in
    *in <- put *in, prev:offset, result
  }
  return result  # needed explicitly because we need to replace 'in' with 'result'
]

def first in:address:duplex-list:_elem -> result:_elem [
  local-scope
  load-ingredients
  return-unless in, 0
  result <- get *in, value:offset
]

def next in:address:duplex-list:_elem -> result:address:duplex-list:_elem/contained-in:in [
  local-scope
  load-ingredients
  return-unless in, 0
  result <- get *in, next:offset
]

def prev in:address:duplex-list:_elem -> result:address:duplex-list:_elem/contained-in:in [
  local-scope
  load-ingredients
  return-unless in, 0
  result <- get *in, prev:offset
  return result
]

scenario duplex-list-handling [
  run [
    local-scope
    # reserve locations 0-9 to check for missing null check
    10:number/raw <- copy 34
    11:number/raw <- copy 35
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:duplex-list:character <- copy list
    20:character/raw <- first list2
    list2 <- next list2
    21:character/raw <- first list2
    list2 <- next list2
    22:character/raw <- first list2
    30:address:duplex-list:character/raw <- next list2
    31:character/raw <- first 30:address:duplex-list:character/raw
    32:address:duplex-list:character/raw <- next 30:address:duplex-list:character/raw
    33:address:duplex-list:character/raw <- prev 30:address:duplex-list:character/raw
    list2 <- prev list2
    40:character/raw <- first list2
    list2 <- prev list2
    41:character/raw <- first list2
    50:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    0 <- 0  # no modifications to null pointers
    10 <- 34
    11 <- 35
    20 <- 5  # scanning next
    21 <- 4
    22 <- 3
    30 <- 0  # null
    31 <- 0  # first of null
    32 <- 0  # next of null
    33 <- 0  # prev of null
    40 <- 4  # then start scanning prev
    41 <- 5
    50 <- 1  # list back at start
  ]
]

# insert 'x' after 'in'
def insert x:_elem, in:address:duplex-list:_elem -> in:address:duplex-list:_elem [
  local-scope
  load-ingredients
  new-node:address:duplex-list:_elem <- new {(duplex-list _elem): type}
  *new-node <- put *new-node, value:offset, x
  # save old next before changing it
  next-node:address:duplex-list:_elem <- get *in, next:offset
  *in <- put *in, next:offset, new-node
  *new-node <- put *new-node, prev:offset, in
  *new-node <- put *new-node, next:offset, next-node
  return-unless next-node
  *next-node <- put *next-node, prev:offset, new-node
]

scenario inserting-into-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:duplex-list:character <- next list  # inside list
    list2 <- insert 6, list2
    # check structure like before
    list2 <- copy list
    10:character/raw <- first list2
    list2 <- next list2
    11:character/raw <- first list2
    list2 <- next list2
    12:character/raw <- first list2
    list2 <- next list2
    13:character/raw <- first list2
    list2 <- prev list2
    20:character/raw <- first list2
    list2 <- prev list2
    21:character/raw <- first list2
    list2 <- prev list2
    22:character/raw <- first list2
    30:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    10 <- 5  # scanning next
    11 <- 4
    12 <- 6  # inserted element
    13 <- 3
    20 <- 6  # then prev
    21 <- 4
    22 <- 5
    30 <- 1  # list back at start
  ]
]

scenario inserting-at-end-of-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:duplex-list:character <- next list  # inside list
    list2 <- next list2  # now at end of list
    list2 <- insert 6, list2
    # check structure like before
    list2 <- copy list
    10:character/raw <- first list2
    list2 <- next list2
    11:character/raw <- first list2
    list2 <- next list2
    12:character/raw <- first list2
    list2 <- next list2
    13:character/raw <- first list2
    list2 <- prev list2
    20:character/raw <- first list2
    list2 <- prev list2
    21:character/raw <- first list2
    list2 <- prev list2
    22:character/raw <- first list2
    30:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    10 <- 5  # scanning next
    11 <- 4
    12 <- 3
    13 <- 6  # inserted element
    20 <- 3  # then prev
    21 <- 4
    22 <- 5
    30 <- 1  # list back at start
  ]
]

scenario inserting-after-start-of-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list <- insert 6, list
    # check structure like before
    list2:address:duplex-list:character <- copy list
    10:character/raw <- first list2
    list2 <- next list2
    11:character/raw <- first list2
    list2 <- next list2
    12:character/raw <- first list2
    list2 <- next list2
    13:character/raw <- first list2
    list2 <- prev list2
    20:character/raw <- first list2
    list2 <- prev list2
    21:character/raw <- first list2
    list2 <- prev list2
    22:character/raw <- first list2
    30:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    10 <- 5  # scanning next
    11 <- 6  # inserted element
    12 <- 4
    13 <- 3
    20 <- 4  # then prev
    21 <- 6
    22 <- 5
    30 <- 1  # list back at start
  ]
]

# remove 'x' from its surrounding list 'in'
#
# Returns null if and only if list is empty. Beware: in that case any other
# pointers to the head are now invalid.
def remove x:address:duplex-list:_elem/contained-in:in, in:address:duplex-list:_elem -> in:address:duplex-list:_elem [
  local-scope
  load-ingredients
  # if 'x' is null, return
  return-unless x
  next-node:address:duplex-list:_elem <- get *x, next:offset
  prev-node:address:duplex-list:_elem <- get *x, prev:offset
  # null x's pointers
  *x <- put *x, next:offset, 0
  *x <- put *x, prev:offset, 0
  # if next-node is not null, set its prev pointer
  {
    break-unless next-node
    *next-node <- put *next-node, prev:offset, prev-node
  }
  # if prev-node is not null, set its next pointer and return
  {
    break-unless prev-node
    *prev-node <- put *prev-node, next:offset, next-node
    return
  }
  # if prev-node is null, then we removed the head node at 'in'
  # return the new head rather than the old 'in'
  return next-node
]

scenario removing-from-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:duplex-list:character <- next list  # second element
    list <- remove list2, list
    10:boolean/raw <- equal list2, 0
    # check structure like before
    list2 <- copy list
    11:character/raw <- first list2
    list2 <- next list2
    12:character/raw <- first list2
    20:address:duplex-list:character/raw <- next list2
    list2 <- prev list2
    30:character/raw <- first list2
    40:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    10 <- 0  # remove returned non-null
    11 <- 5  # scanning next, skipping deleted element
    12 <- 3
    20 <- 0  # no more elements
    30 <- 5  # prev of final element
    40 <- 1  # list back at start
  ]
]

scenario removing-from-start-of-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list <- remove list, list
    # check structure like before
    list2:address:duplex-list:character <- copy list
    10:character/raw <- first list2
    list2 <- next list2
    11:character/raw <- first list2
    20:address:duplex-list:character/raw <- next list2
    list2 <- prev list2
    30:character/raw <- first list2
    40:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    10 <- 4  # scanning next, skipping deleted element
    11 <- 3
    20 <- 0  # no more elements
    30 <- 4  # prev of final element
    40 <- 1  # list back at start
  ]
]

scenario removing-from-end-of-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    # delete last element
    list2:address:duplex-list:character <- next list
    list2 <- next list2
    list <- remove list2, list
    10:boolean/raw <- equal list2, 0
    # check structure like before
    list2 <- copy list
    11:character/raw <- first list2
    list2 <- next list2
    12:character/raw <- first list2
    20:address:duplex-list:character/raw <- next list2
    list2 <- prev list2
    30:character/raw <- first list2
    40:boolean/raw <- equal list, list2
  ]
  memory-should-contain [
    10 <- 0  # remove returned non-null
    11 <- 5  # scanning next, skipping deleted element
    12 <- 4
    20 <- 0  # no more elements
    30 <- 5  # prev of final element
    40 <- 1  # list back at start
  ]
]

scenario removing-from-singleton-duplex-list [
  run [
    local-scope
    list:address:duplex-list:character <- push 3, 0
    list <- remove list, list
    1:number/raw <- copy list
  ]
  memory-should-contain [
    1 <- 0  # back to an empty list
  ]
]

# remove values between 'start' and 'end' (both exclusive).
# also clear pointers back out from start/end for hygiene.
# set end to 0 to delete everything past start.
# can't set start to 0 to delete everything before end, because there's no
# clean way to return the new head pointer.
def remove-between start:address:duplex-list:_elem, end:address:duplex-list:_elem/contained-in:start -> start:address:duplex-list:_elem [
  local-scope
  load-ingredients
  next:address:duplex-list:_elem <- get *start, next:offset
  nothing-to-delete?:boolean <- equal next, end
  return-if nothing-to-delete?
  assert next, [malformed duplex list]
  # start->next->prev = 0
  # start->next = end
  *next <- put *next, prev:offset, 0
  *start <- put *start, next:offset, end
  return-unless end
  # end->prev->next = 0
  # end->prev = start
  prev:address:duplex-list:_elem <- get *end, prev:offset
  assert prev, [malformed duplex list - 2]
  *prev <- put *prev, next:offset, 0
  *end <- put *end, prev:offset, start
]

scenario remove-range [
  # construct a duplex list with six elements [13, 14, 15, 16, 17, 18]
  local-scope
  list:address:duplex-list:character <- push 18, 0
  list <- push 17, list
  list <- push 16, list
  list <- push 15, list
  list <- push 14, list
  list <- push 13, list
  1:address:duplex-list:character/raw <- copy list  # save list
  run [
    local-scope
    list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw  # restore list
    # delete 16 onwards
    # first pointer: to the third element
    list2:address:duplex-list:character <- next list
    list2 <- next list2
    list2 <- remove-between list2, 0
    # now check the list
    10:character/raw <- get *list, value:offset
    list <- next list
    11:character/raw <- get *list, value:offset
    list <- next list
    12:character/raw <- get *list, value:offset
    20:address:duplex-list:character/raw <- next list
  ]
  memory-should-contain [
    10 <- 13
    11 <- 14
    12 <- 15
    20 <- 0
  ]
]

scenario remove-range-to-final [
  local-scope
  # construct a duplex list with six elements [13, 14, 15, 16, 17, 18]
  list:address:duplex-list:character <- push 18, 0
  list <- push 17, list
  list <- push 16, list
  list <- push 15, list
  list <- push 14, list
  list <- push 13, list
  1:address:duplex-list:character/raw <- copy list  # save list
  run [
    local-scope
    list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw  # restore list
    # delete 15, 16 and 17
    # start pointer: to the second element
    list2:address:duplex-list:character <- next list
    # end pointer: to the last (sixth) element
    end:address:duplex-list:character <- next list2
    end <- next end
    end <- next end
    end <- next end
    remove-between list2, end
    # now check the list
    10:character/raw <- get *list, value:offset
    list <- next list
    11:character/raw <- get *list, value:offset
    list <- next list
    12:character/raw <- get *list, value:offset
    20:address:duplex-list:character/raw <- next list
  ]
  memory-should-contain [
    10 <- 13
    11 <- 14
    12 <- 18
    20 <- 0  # no more elements
  ]
]

scenario remove-range-empty [
  local-scope
  # construct a duplex list with three elements [13, 14, 15]
  list:address:duplex-list:character <- push 15, 0
  list <- push 14, list
  list <- push 13, list
  1:address:duplex-list:character/raw <- copy list  # save list
  run [
    local-scope
    list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw  # restore list
    # delete between first and second element (i.e. nothing)
    list2:address:duplex-list:character <- next list
    remove-between list, list2
    # now check the list
    10:character/raw <- get *list, value:offset
    list <- next list
    11:character/raw <- get *list, value:offset
    list <- next list
    12:character/raw <- get *list, value:offset
    20:address:duplex-list:character/raw <- next list
  ]
  # no change
  memory-should-contain [
    10 <- 13
    11 <- 14
    12 <- 15
    20 <- 0
  ]
]

scenario remove-range-to-end [
  local-scope
  # construct a duplex list with six elements [13, 14, 15, 16, 17, 18]
  list:address:duplex-list:character <- push 18, 0
  list <- push 17, list
  list <- push 16, list
  list <- push 15, list
  list <- push 14, list
  list <- push 13, list
  1:address:duplex-list:character/raw <- copy list  # save list
  run [
    local-scope
    list:address:duplex-list:character <- copy 1:address:duplex-list:character/raw  # restore list
    # remove the third element and beyond
    list2:address:duplex-list:character <- next list
    remove-between list2, 0
    # now check the list
    10:character/raw <- get *list, value:offset
    list <- next list
    11:character/raw <- get *list, value:offset
    20:address:duplex-list:character/raw <- next list
  ]
  memory-should-contain [
    10 <- 13
    11 <- 14
    20 <- 0
  ]
]

# insert list beginning at 'new' after 'in'
def insert-range in:address:duplex-list:_elem, start:address:duplex-list:_elem/contained-in:in -> in:address:duplex-list:_elem [
  local-scope
  load-ingredients
  return-unless in
  return-unless start
  end:address:duplex-list:_elem <- copy start
  {
    next:address:duplex-list:_elem <- next end/insert-range
    break-unless next
    end <- copy next
    loop
  }
  next:address:duplex-list:_elem <- next in
  *end <- put *end, next:offset, next
  {
    break-unless next
    *next <- put *next, prev:offset, end
  }
  *in <- put *in, next:offset, start
  *start <- put *start, prev:offset, in
]

def append in:address:duplex-list:_elem, new:address:duplex-list:_elem/contained-in:in -> in:address:duplex-list:_elem [
  local-scope
  load-ingredients
  last:address:duplex-list:_elem <- last in
  *last <- put *last, next:offset, new
  return-unless new
  *new <- put *new, prev:offset, last
]

def last in:address:duplex-list:_elem -> result:address:duplex-list:_elem [
  local-scope
  load-ingredients
  result <- copy in
  {
    next:address:duplex-list:_elem <- next result
    break-unless next
    result <- copy next
    loop
  }
]

# helper for debugging
def dump-from x:address:duplex-list:_elem [
  local-scope
  load-ingredients
  $print x, [: ]
  {
    break-unless x
    c:_elem <- get *x, value:offset
    $print c, [ ]
    x <- next x
    {
      is-newline?:boolean <- equal c, 10/newline
      break-unless is-newline?
      $print 10/newline
      $print x, [: ]
    }
    loop
  }
  $print 10/newline, [---], 10/newline
]