|
| 1 | +-- |
| 2 | +-- Tests for the text module |
| 3 | +-- |
| 4 | +local text = require 'text' |
| 5 | +local tasty = require 'tasty' |
| 6 | + |
| 7 | +local group = tasty.test_group |
| 8 | +local test = tasty.test_case |
| 9 | +local assert = tasty.assert |
| 10 | + |
| 11 | +return { |
| 12 | + group 'len' { |
| 13 | + test('ASCII', function () |
| 14 | + tasty.assert.are_equal(text.len 'five!', 5) |
| 15 | + end), |
| 16 | + test('German sz', function () |
| 17 | + tasty.assert.are_equal(text.len 'Straße', 6) |
| 18 | + end), |
| 19 | + test('string with small letter e accute', function () |
| 20 | + tasty.assert.are_equal(text.len 'Chartie', 7) |
| 21 | + end), |
| 22 | + test('Unicode snowman', function () |
| 23 | + tasty.assert.are_equal(text.len '☃', 1) |
| 24 | + end) |
| 25 | + }, |
| 26 | + |
| 27 | + group 'lower' { |
| 28 | + test('uppercase ASCII', function () |
| 29 | + assert.are_equal(text.lower 'YELLING', 'yelling') |
| 30 | + end), |
| 31 | + test('lowercase ASCII', function () |
| 32 | + assert.are_equal(text.lower 'talking', 'talking') |
| 33 | + end), |
| 34 | + test('capitalized word with umlaut', function () |
| 35 | + assert.are_equal(text.lower 'Lübeck', 'lübeck') |
| 36 | + end), |
| 37 | + }, |
| 38 | + |
| 39 | + group 'upper' { |
| 40 | + test('uppercase ASCII', function () |
| 41 | + assert.are_equal(text.upper 'YELLING', 'YELLING') |
| 42 | + end), |
| 43 | + test('lowercase ASCII', function () |
| 44 | + assert.are_equal(text.upper 'silence', 'SILENCE') |
| 45 | + end), |
| 46 | + test('capitalized word with umlaut', function () |
| 47 | + assert.are_equal(text.upper 'Lübeck', 'LÜBECK') |
| 48 | + end), |
| 49 | + test('German ß becomes double S', function () |
| 50 | + assert.are_equal(text.upper 'Spaß', 'SPASS') |
| 51 | + end), |
| 52 | + }, |
| 53 | + |
| 54 | + group 'reverse' { |
| 55 | + test('être becomes ertê', function () |
| 56 | + assert.are_equal(text.reverse 'être', 'ertê') |
| 57 | + end) |
| 58 | + }, |
| 59 | + |
| 60 | + group 'sub' { |
| 61 | + test('behaves like string.sub for ASCII text', function () |
| 62 | + local hw = 'Hello, World' |
| 63 | + assert.are_equal(text.sub(hw, 6), string.sub(hw, 6)) |
| 64 | + assert.are_equal(text.sub(hw, -1, -1), string.sub(hw, -1, -1)) |
| 65 | + assert.are_equal(text.sub(hw, -7, -2), string.sub(hw, -7, -2)) |
| 66 | + assert.are_equal(text.sub(hw, 7, -2), string.sub(hw, 7, -2)) |
| 67 | + assert.are_equal(text.sub(hw, 1, 5), string.sub(hw, 1, 5)) |
| 68 | + assert.are_equal(text.sub(hw, 5, 0), string.sub(hw, 5, 0)) |
| 69 | + assert.are_equal(text.sub(hw, 0, 2), string.sub(hw, 0, 2)) |
| 70 | + assert.are_equal(text.sub(hw, -19, 5), string.sub(hw, -19, 5)) |
| 71 | + end), |
| 72 | + test('respects UTF-8', function () |
| 73 | + assert.are_equal(text.sub('Für dich', 5), 'dich') |
| 74 | + assert.are_equal(text.sub('☢ radioactive', 0, 1), '☢') |
| 75 | + assert.are_equal(text.sub('☢ radioactive', -11, -1), 'radioactive') |
| 76 | + end) |
| 77 | + } |
| 78 | +} |
0 commit comments