summary refs log tree commit diff stats
path: root/lib/system/chcks.nim
Commit message (Expand)AuthorAgeFilesLines
* fixes fieldDefect loses enum type info in ORC; consistent with VM and refc (#...ringabout2023-05-291-0/+4
* moderate system cleanup & refactor (#20355)metagn2022-09-281-2/+2
* move formatfloat out of system (#20195)ringabout2022-08-241-0/+2
* Better range error messages (#19867)Tanguy2022-06-151-0/+3
* Update chcks.nim (#19540)rockcavera2022-02-171-1/+1
* properly fix #10053 ; `FieldDefect` msg now shows discriminant value + linein...Timothee Cour2021-08-131-0/+10
* [os:standalone]fix #14011 (#17564)flywind2021-03-291-2/+8
* fixes #15210 [backport:1.2] (#15237)Andreas Rumpf2020-08-311-0/+3
* Error -> Defect for defects (#13908)Jacek Sieka2020-04-281-18/+18
* catchable defects (#13626)Andreas Rumpf2020-03-121-3/+15
* fixes #10053 (#11951)Timothee Cour2019-08-151-1/+1
* styleCheck: make the compiler and large parts of the stdlib compatible with -...Araq2019-07-101-2/+2
* fixes #11205Araq2019-05-281-0/+5
* hotfix for 32bit unsigned 'range' checking; incomplete, unknown why some oper...Araq2019-05-271-0/+6
* --newruntime: work in progressAndreas Rumpf2019-03-141-43/+45
* code cleanup: there is no MoveError and sinks are always availableAndreas Rumpf2019-03-041-5/+0
* Initial version of the hot-code reloading support for native targets (#10729)zah2019-02-261-1/+1
* helpers2 now has a real nameAraq2019-02-071-1/+1
* refs #9880 show index and bound in lots of `index out of bounds` errorsTimothee Cour2018-12-091-1/+8
* further steps in implementing sink parameters; refs #7041Araq2018-03-301-0/+5
* Implement language feature #6885 (#6954)cooldome2017-12-241-1/+0
* fixes #5599 (#5610)Andreas Rumpf2017-03-261-1/+5
* fix types of ansi_c/sysio to more closely match C ABIJacek Sieka2016-06-051-1/+0
* Move the noreturn pragma to sysFataldef2015-05-051-3/+3
* Get rid of more deprecation warnings by renaming exceptionsdef2015-01-271-2/+2
* system files use new identifiersAraq2014-08-231-7/+7
* the big renamefest: first stepsAraq2014-08-221-1/+1
* optimized method dispatchersAraq2014-06-121-0/+22
* case consistency: next stepsAraq2013-12-291-1/+1
* case consistency part 4Araq2013-12-271-1/+1
* --os:standalone works againAraq2013-06-301-0/+77
tick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #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 */
-- major tests for drawings
-- We minimize assumptions about specific pixels, and try to test at the level
-- of specific shapes. In particular, no tests of freehand drawings.

function test_draw_line()
  io.write('\ntest_draw_line')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  Current_drawing_mode = 'line'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_line/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_line/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_line/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_line/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes')
  -- draw a line
  App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
  App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  check_eq(#Lines[1].shapes, 1, 'F - test_draw_line/#shapes')
  check_eq(#Lines[1].points, 2, 'F - test_draw_line/#points')
  local drawing = Lines[1]
  check_eq(drawing.shapes[1].mode, 'line', 'F - test_draw_line/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'F - test_draw_line/p1:x')
  check_eq(p1.y, 6, 'F - test_draw_line/p1:y')
  check_eq(p2.x, 35, 'F - test_draw_line/p2:x')
  check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
end

function test_draw_horizontal_line()
  io.write('\ntest_draw_horizontal_line')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  Current_drawing_mode = 'manhattan'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_horizontal_line/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_horizontal_line/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_horizontal_line/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_horizontal_line/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_horizontal_line/baseline/#shapes')
  -- draw a line that is more horizontal than vertical
  App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
  App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+26, 1)
  check_eq(#Lines[1].shapes, 1, 'F - test_draw_horizontal_line/#shapes')
  check_eq(#Lines[1].points, 2, 'F - test_draw_horizontal_line/#points')
  local drawing = Lines[1]
  check_eq(drawing.shapes[1].mode, 'manhattan', 'F - test_draw_horizontal_line/shape_mode')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'F - test_draw_horizontal_line/p1:x')
  check_eq(p1.y, 6, 'F - test_draw_horizontal_line/p1:y')
  check_eq(p2.x, 35, 'F - test_draw_horizontal_line/p2:x')
  check_eq(p2.y, p1.y, 'F - test_draw_horizontal_line/p2:y')
end

function test_draw_circle()
  io.write('\ntest_draw_circle')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  Current_drawing_mode = 'line'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_circle/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_circle/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_circle/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_circle/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_circle/baseline/#shapes')
  -- draw a circle
  App.mouse_move(Margin_left+4, Margin_top+Drawing_padding_top+4)  -- hover on drawing
  App.run_after_keychord('C-o')
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_mouse_release(Margin_left+35+30, Margin_top+Drawing_padding_top+36, 1)
  check_eq(#Lines[1].shapes, 1, 'F - test_draw_circle/#shapes')
  check_eq(#Lines[1].points, 1, 'F - test_draw_circle/#points')
  local drawing = Lines[1]
  check_eq(drawing.shapes[1].mode, 'circle', 'F - test_draw_horizontal_line/shape_mode')
  check_eq(drawing.shapes[1].radius, 30, 'F - test_draw_circle/radius')
  local center = drawing.points[drawing.shapes[1].center]
  check_eq(center.x, 35, 'F - test_draw_circle/center:x')
  check_eq(center.y, 36, 'F - test_draw_circle/center:y')
end

function test_keys_do_not_affect_shape_when_mouse_up()
  io.write('\ntest_keys_do_not_affect_shape_when_mouse_up')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  Current_drawing_mode = 'line'
  App.draw()
  -- hover over drawing and press 'o' without holding mouse
  App.mouse_move(Margin_left+4, Margin_top+Drawing_padding_top+4)  -- hover on drawing
  App.run_after_keychord('o')
  -- no change to drawing mode
  check_eq(Current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode')
  -- no change to text either because we didn't run the textinput event
end

function test_draw_circle_mid_stroke()
  io.write('\ntest_draw_circle_mid_stroke')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  Current_drawing_mode = 'line'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_circle_mid_stroke/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_circle_mid_stroke/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_circle_mid_stroke/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_circle_mid_stroke/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_circle_mid_stroke/baseline/#shapes')
  -- draw a circle
  App.mouse_move(Margin_left+4, Margin_top+Drawing_padding_top+4)  -- hover on drawing
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_keychord('o')
  App.run_after_mouse_release(Margin_left+35+30, Margin_top+Drawing_padding_top+36, 1)
  check_eq(#Lines[1].shapes, 1, 'F - test_draw_circle_mid_stroke/#shapes')
  check_eq(#Lines[1].points, 1, 'F - test_draw_circle_mid_stroke/#points')
  local drawing = Lines[1]
  check_eq(drawing.shapes[1].mode, 'circle', 'F - test_draw_horizontal_line/shape_mode')
  check_eq(drawing.shapes[1].radius, 30, 'F - test_draw_circle_mid_stroke/radius')
  local center = drawing.points[drawing.shapes[1].center]
  check_eq(center.x, 35, 'F - test_draw_circle_mid_stroke/center:x')
  check_eq(center.y, 36, 'F - test_draw_circle_mid_stroke/center:y')
end

function test_draw_arc()
  io.write('\ntest_draw_arc')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  Current_drawing_mode = 'circle'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_arc/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_arc/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_arc/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_arc/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_arc/baseline/#shapes')
  -- draw an arc
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.mouse_move(Margin_left+35+30, Margin_top+Drawing_padding_top+36)
  App.run_after_keychord('a')  -- arc mode
  App.run_after_mouse_release(Margin_left+35+50, Margin_top+Drawing_padding_top+36+50, 1)  -- 45°
  check_eq(#Lines[1].shapes, 1, 'F - test_draw_arc/#shapes')
  check_eq(#Lines[1].points, 2, 'F - test_draw_arc/#points')
  local drawing = Lines[1]
  check_eq(drawing.shapes[1].mode, 'arc', 'F - test_draw_horizontal_line/shape_mode')
  local arc = drawing.shapes[1]
  check_eq(arc.radius, 30, 'F - test_draw_arc/radius')
  local center = drawing.points[arc.center]
  check_eq(center.x, 35, 'F - test_draw_arc/center:x')
  check_eq(center.y, 36, 'F - test_draw_arc/center:y')
  check_eq(arc.start_angle, 0, 'F - test_draw_arc/start:angle')
  check_eq(arc.end_angle, math.pi/4, 'F - test_draw_arc/end:angle')
end