summaryrefslogtreecommitdiffhomepage
path: root/samples/10_advanced_debugging/03_unit_tests
diff options
context:
space:
mode:
authorAmir Rajan <[email protected]>2021-08-07 00:13:33 -0500
committerAmir Rajan <[email protected]>2021-08-07 00:13:33 -0500
commita503afe87619ff82201c0a43818fa1c3f070a548 (patch)
tree0b228a6456d17f6d0c6ea54c9ecd6a045ddbdf59 /samples/10_advanced_debugging/03_unit_tests
parentbea150381f495630f92f89d23d5f3445ec289b2d (diff)
downloaddragonruby-game-toolkit-contrib-a503afe87619ff82201c0a43818fa1c3f070a548.tar.gz
dragonruby-game-toolkit-contrib-a503afe87619ff82201c0a43818fa1c3f070a548.zip
Samples folder synced.
Diffstat (limited to 'samples/10_advanced_debugging/03_unit_tests')
-rw-r--r--samples/10_advanced_debugging/03_unit_tests/benchmark_api_tests.rb43
-rw-r--r--samples/10_advanced_debugging/03_unit_tests/pretty_format_tests.rb130
-rw-r--r--samples/10_advanced_debugging/03_unit_tests/run-bash.sh4
-rw-r--r--samples/10_advanced_debugging/03_unit_tests/run-tests.sh27
4 files changed, 190 insertions, 14 deletions
diff --git a/samples/10_advanced_debugging/03_unit_tests/benchmark_api_tests.rb b/samples/10_advanced_debugging/03_unit_tests/benchmark_api_tests.rb
new file mode 100644
index 0000000..2c06f1a
--- /dev/null
+++ b/samples/10_advanced_debugging/03_unit_tests/benchmark_api_tests.rb
@@ -0,0 +1,43 @@
+def test_benchmark_api args, assert
+ result = args.gtk.benchmark iterations: 100,
+ only_one: -> () {
+ r = 0
+ (1..100).each do |i|
+ r += 1
+ end
+ }
+
+ assert.equal! result.first_place.name, :only_one
+
+ result = args.gtk.benchmark iterations: 100,
+ iterations_100: -> () {
+ r = 0
+ (1..100).each do |i|
+ r += 1
+ end
+ },
+ iterations_50: -> () {
+ r = 0
+ (1..50).each do |i|
+ r += 1
+ end
+ }
+
+ assert.equal! result.first_place.name, :iterations_50
+
+ result = args.gtk.benchmark iterations: 1,
+ iterations_100: -> () {
+ r = 0
+ (1..100).each do |i|
+ r += 1
+ end
+ },
+ iterations_50: -> () {
+ r = 0
+ (1..50).each do |i|
+ r += 1
+ end
+ }
+
+ assert.equal! result.too_small_to_measure, true
+end
diff --git a/samples/10_advanced_debugging/03_unit_tests/pretty_format_tests.rb b/samples/10_advanced_debugging/03_unit_tests/pretty_format_tests.rb
new file mode 100644
index 0000000..6ac7b05
--- /dev/null
+++ b/samples/10_advanced_debugging/03_unit_tests/pretty_format_tests.rb
@@ -0,0 +1,130 @@
+def H opts
+ opts
+end
+
+def A *opts
+ opts
+end
+
+def assert_format args, assert, hash, expected
+ actual = args.fn.pretty_format hash
+ assert.are_equal! actual, expected
+end
+
+def test_pretty_print args, assert
+ # =============================
+ # hash with single value
+ # =============================
+ input = (H first_name: "John")
+ expected = <<-S
+{:first_name "John"}
+S
+ (assert_format args, assert, input, expected)
+
+ # =============================
+ # hash with two values
+ # =============================
+ input = (H first_name: "John", last_name: "Smith")
+ expected = <<-S
+{:first_name "John"
+ :last_name "Smith"}
+S
+
+ (assert_format args, assert, input, expected)
+
+ # =============================
+ # hash with inner hash
+ # =============================
+ input = (H first_name: "John",
+ last_name: "Smith",
+ middle_initial: "I",
+ so: (H first_name: "Pocahontas",
+ last_name: "Tsenacommacah"),
+ friends: (A (H first_name: "Side", last_name: "Kick"),
+ (H first_name: "Tim", last_name: "Wizard")))
+ expected = <<-S
+{:first_name "John"
+ :last_name "Smith"
+ :middle_initial "I"
+ :so {:first_name "Pocahontas"
+ :last_name "Tsenacommacah"}
+ :friends [{:first_name "Side"
+ :last_name "Kick"}
+ {:first_name "Tim"
+ :last_name "Wizard"}]}
+S
+
+ (assert_format args, assert, input, expected)
+
+ # =============================
+ # array with one value
+ # =============================
+ input = (A 1)
+ expected = <<-S
+[1]
+S
+ (assert_format args, assert, input, expected)
+
+ # =============================
+ # array with multiple values
+ # =============================
+ input = (A 1, 2, 3)
+ expected = <<-S
+[1
+ 2
+ 3]
+S
+ (assert_format args, assert, input, expected)
+
+ # =============================
+ # array with multiple values hashes
+ # =============================
+ input = (A (H first_name: "Side", last_name: "Kick"),
+ (H first_name: "Tim", last_name: "Wizard"))
+ expected = <<-S
+[{:first_name "Side"
+ :last_name "Kick"}
+ {:first_name "Tim"
+ :last_name "Wizard"}]
+S
+
+ (assert_format args, assert, input, expected)
+end
+
+def test_nested_nested args, assert
+ # =============================
+ # nested array in nested hash
+ # =============================
+ input = (H type: :root,
+ text: "Root",
+ children: (A (H level: 1,
+ text: "Level 1",
+ children: (A (H level: 2,
+ text: "Level 2",
+ children: [])))))
+
+ expected = <<-S
+{:type :root
+ :text "Root"
+ :children [{:level 1
+ :text "Level 1"
+ :children [{:level 2
+ :text "Level 2"
+ :children []}]}]}
+
+S
+
+ (assert_format args, assert, input, expected)
+end
+
+def test_scene args, assert
+ script = <<-S
+* Scene 1
+** Narrator
+They say happy endings don't exist.
+** Narrator
+They say true love is a lie.
+S
+ input = parse_org args, script
+ puts (args.fn.pretty_format input)
+end
diff --git a/samples/10_advanced_debugging/03_unit_tests/run-bash.sh b/samples/10_advanced_debugging/03_unit_tests/run-bash.sh
deleted file mode 100644
index 005077b..0000000
--- a/samples/10_advanced_debugging/03_unit_tests/run-bash.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-sh ./amir-build-and-run.sh --eval samples/99_zz_gtk_unit_tests/geometry_tests.rb --no-tick
-sh ./amir-build-and-run.sh --eval samples/99_zz_gtk_unit_tests/parsing_tests.rb --no-tick
-sh ./amir-build-and-run.sh --eval samples/99_zz_gtk_unit_tests/http_tests.rb --no-tick
-sh ./amir-build-and-run.sh --eval samples/99_zz_gtk_unit_tests/array_to_primitive_tests.rb --no-tick
diff --git a/samples/10_advanced_debugging/03_unit_tests/run-tests.sh b/samples/10_advanced_debugging/03_unit_tests/run-tests.sh
index e551edf..d8b1a4a 100644
--- a/samples/10_advanced_debugging/03_unit_tests/run-tests.sh
+++ b/samples/10_advanced_debugging/03_unit_tests/run-tests.sh
@@ -1,10 +1,17 @@
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/require_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/gen_docs.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/geometry_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/http_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/object_to_primitive_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/parsing_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/require_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/serialize_deserialize_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/state_serialization_experimental_tests.rb
-./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/suggest_autocompletion_tests.rb
+# fswatch ./samples/10_advanced_debugging/03_unit_tests/benchmark_api_tests.rb | xargs -n1 -I{} sh ./samples/10_advanced_debugging/03_unit_tests/run-tests.sh
+# set -e
+# rake
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/require_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/gen_docs.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/geometry_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/http_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/object_to_primitive_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/parsing_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/require_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/serialize_deserialize_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/state_serialization_experimental_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/suggest_autocompletion_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/nil_coercion_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/fn_tests.rb
+# ./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/pretty_format_test.rb
+./dragonruby mygame --test samples/10_advanced_debugging/03_unit_tests/benchmark_api_tests.rb