1local tasty = require 'tasty'
2local types = require 'pandoc.types'
3local Version = types.Version
5local assert = tasty.assert
6local test = tasty.test_case
7local group = tasty.test_group
13 test('has type `userdata`', function ()
14 assert.are_same(type(Version {2}), 'userdata')
16 test('accepts list of integers', function ()
17 assert.are_same(type(Version {2, 7, 3}), 'userdata')
19 test('accepts a single integer', function ()
20 assert.are_same(Version(5), Version {5})
22 test('accepts version as string', function ()
28 test('non-version string is rejected', function ()
30 function () Version '11friends' end,
37 test('smaller (equal) than', function ()
38 assert.is_truthy(Version {2, 58, 3} < Version {2, 58, 4})
39 assert.is_falsy(Version {2, 60, 1} < Version {2, 59, 2})
40 assert.is_truthy(Version {0, 14, 3} < Version {0, 14, 3, 1})
41 assert.is_truthy(Version {3, 58, 3} <= Version {4})
42 assert.is_truthy(Version {0, 14, 3} <= Version {0, 14, 3, 1})
44 test('larger (equal) than', function ()
45 assert.is_truthy(Version{2,58,3} > Version {2, 57, 4})
46 assert.is_truthy(Version{2,58,3} > Version {2, 58, 2})
47 assert.is_truthy(Version {0, 8} >= Version {0, 8})
48 assert.is_falsy(Version {0, 8} >= Version {0, 8, 2})
50 test('equality', function ()
51 assert.is_truthy(Version '8.8', Version {8, 8})
53 test('second argument can be a version string', function ()
54 assert.is_truthy(Version '8' < '9.1')
55 assert.is_falsy(Version '8.8' < '8.7')
59 group 'list-like behavior' {
60 test('can access version component numbers', function ()
61 local version = Version '2.7.3'
62 assert.is_nil(version[0])
63 assert.are_equal(version[1], 2)
64 assert.are_equal(version[2], 7)
65 assert.are_equal(version[3], 3)
67 test('can be iterated over', function ()
68 local version_list = {2, 7, 3}
70 for i, v in pairs(Version(version_list)) do
71 assert.are_equal(v, version_list[i])
74 assert.are_equal(final_index, 3)
76 test('length is the number of components', function ()
77 assert.are_equal(#(Version '0'), 1)
78 assert.are_equal(#(Version '1.6'), 2)
79 assert.are_equal(#(Version '8.7.5'), 3)
80 assert.are_equal(#(Version '2.9.1.5'), 4)
84 group 'conversion to string' {
85 test('converting from and to string is a noop', function ()
86 local version_string = '1.19.4'
87 assert.are_equal(tostring(Version(version_string)), version_string)
91 group 'convenience functions' {
92 test('throws error if version is too old', function ()
93 local actual = Version {2, 8}
94 local expected = Version {2, 9}
96 function () actual:must_be_at_least(expected) end,
97 'expected version 2.9 or newer, got 2.8'
100 test('does nothing if expected version is older than actual', function ()
101 local actual = Version '2.9'
102 local expected = Version '2.8'
103 actual:must_be_at_least(expected)
105 test('does nothing if expected version equals to actual', function ()
106 local actual = Version '2.8'
107 local expected = Version '2.8'
108 actual:must_be_at_least(expected)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list