2014-10-21 22:46:40 +02:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-11-03 23:43:45 +01:00
|
|
|
require_relative './support/foorth_testing'
|
2015-04-12 21:29:54 +02:00
|
|
|
gem 'minitest'
|
2014-11-04 06:26:00 +01:00
|
|
|
require 'minitest/autorun'
|
2014-12-20 01:17:23 +01:00
|
|
|
require 'minitest_visible'
|
2014-10-21 22:46:40 +02:00
|
|
|
|
|
|
|
#Test the standard fOOrth library.
|
2015-04-12 21:29:54 +02:00
|
|
|
class StdioLibraryTester < Minitest::Test
|
2014-10-21 22:46:40 +02:00
|
|
|
|
|
|
|
include XfOOrthTestExtensions
|
|
|
|
|
2014-12-20 01:17:23 +01:00
|
|
|
#Track mini-test progress.
|
2016-02-18 18:23:04 +01:00
|
|
|
include MinitestVisible
|
2014-10-21 22:46:40 +02:00
|
|
|
|
|
|
|
def test_the_dot
|
|
|
|
foorth_output('4 .', "4")
|
|
|
|
foorth_output('-4 .', "-4")
|
|
|
|
foorth_output('"test" .', "test")
|
|
|
|
foorth_output('Object .name .', "Object")
|
2014-10-22 21:14:54 +02:00
|
|
|
end
|
2014-10-21 22:46:40 +02:00
|
|
|
|
2014-10-22 21:14:54 +02:00
|
|
|
def test_the_dot_quote
|
2014-10-21 22:46:40 +02:00
|
|
|
foorth_output('."test"', "test")
|
|
|
|
end
|
2014-10-22 21:14:54 +02:00
|
|
|
|
|
|
|
def test_the_dot_cr
|
2015-01-25 20:35:39 +01:00
|
|
|
foorth_output('cr', "\n")
|
2014-10-22 21:14:54 +02:00
|
|
|
end
|
|
|
|
|
2014-10-23 20:35:33 +02:00
|
|
|
def test_the_space
|
|
|
|
foorth_output('space', " ")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_the_spaces
|
|
|
|
foorth_output('1 spaces', " ")
|
|
|
|
foorth_output('2 spaces', " ")
|
|
|
|
foorth_output('0 spaces', "")
|
2015-01-25 20:38:08 +01:00
|
|
|
foorth_raises('"apple" spaces')
|
2014-10-23 20:35:33 +02:00
|
|
|
end
|
|
|
|
|
2014-11-27 03:09:38 +01:00
|
|
|
def test_the_emit
|
2015-01-09 21:47:53 +01:00
|
|
|
foorth_output(' 65 .emit', "A")
|
|
|
|
foorth_output('126 .emit', "~")
|
2014-11-27 03:09:38 +01:00
|
|
|
|
2015-01-09 21:47:53 +01:00
|
|
|
foorth_utf8_output('255 .emit', [195, 191])
|
|
|
|
|
|
|
|
foorth_output(' "A123" .emit', "A")
|
|
|
|
foorth_raises('1+1i .emit')
|
2014-11-27 03:09:38 +01:00
|
|
|
end
|
|
|
|
|
2016-10-30 19:45:31 +01:00
|
|
|
#Looks like some unit testing has crept into integration testing. OK.
|
|
|
|
def test_some_formatting
|
|
|
|
assert_equal("1 4\n2 5\n3 ", [1,2,3,4,5].format_foorth_columns(false, 5))
|
|
|
|
assert_equal(["1 4", "2 5", "3 "], [1,2,3,4,5].format_description(5))
|
|
|
|
|
|
|
|
assert_equal(["1 2", "3 4", "5"], "1 2 3 4 5".format_description(5))
|
|
|
|
|
|
|
|
assert_equal([], [].format_description(5))
|
|
|
|
assert_equal([], nil.format_description(5))
|
|
|
|
|
|
|
|
result =
|
|
|
|
"1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 \n" +
|
|
|
|
"2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 \n" +
|
|
|
|
"3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99 \n" +
|
|
|
|
"4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100"
|
|
|
|
|
|
|
|
assert_equal(result, (1..100).to_a.format_foorth_columns(false, 80) )
|
|
|
|
|
|
|
|
data =
|
|
|
|
[["key_largo", "/long_folder_name_one/long_folder_name_two/long_folder_name_three/fine_descriptive_name"],
|
|
|
|
["key_west", "Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. "],
|
|
|
|
["counting", Array.new(100) {|i| i} ],
|
|
|
|
["pie", Math::PI]
|
|
|
|
]
|
|
|
|
|
|
|
|
result =
|
|
|
|
"key_largo /long_folder_name_one/long_folder_name_two/long_folder_name_three/fin\n" +
|
|
|
|
" e_descriptive_name\n" +
|
|
|
|
"key_west Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper\n" +
|
|
|
|
" ubi sub ubi.\n" +
|
|
|
|
"counting 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95\n" +
|
|
|
|
" 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96\n" +
|
|
|
|
" 2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 82 87 92 97\n" +
|
|
|
|
" 3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 83 88 93 98\n" +
|
|
|
|
" 4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94 99\n" +
|
|
|
|
"pie 3.141592653589793"
|
|
|
|
|
2016-10-30 20:04:32 +01:00
|
|
|
assert_equal(result, data.foorth_format_bullets(80))
|
|
|
|
|
|
|
|
assert_equal("", [].foorth_format_bullets(80))
|
|
|
|
|
|
|
|
|
|
|
|
data =
|
|
|
|
{"key_largo" => "/long_folder_name_one/long_folder_name_two/long_folder_name_three/fine_descriptive_name",
|
|
|
|
"key_west" => "Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. Semper ubi sub ubi. ",
|
|
|
|
"counting" => Array.new(100) {|i| i},
|
|
|
|
"pie" => Math::PI
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal(result, data.foorth_format_bullets(80))
|
2016-10-30 19:45:31 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-10-30 22:25:16 +01:00
|
|
|
def test_formatting_some_more
|
|
|
|
foorth_run('5 $chars_per_line !')
|
|
|
|
foorth_equal('[ 1 2 3 4 5 ] .format_columns', ["1 4\n2 5\n3 "])
|
2016-10-31 01:39:39 +01:00
|
|
|
|
2016-10-30 22:25:16 +01:00
|
|
|
foorth_run('80 $chars_per_line !')
|
2016-10-31 01:39:39 +01:00
|
|
|
foorth_equal('[ [ 1 "apple" ] [ 2 "cherry" ] [ 3 "prune" ] ] .format_bullets',
|
|
|
|
["1 apple\n2 cherry\n3 prune"])
|
2016-10-30 22:25:16 +01:00
|
|
|
end
|
|
|
|
|
2014-10-21 22:46:40 +02:00
|
|
|
end
|