|
| 1 | +local T = MiniTest.new_set() |
| 2 | + |
| 3 | +local cases = { |
| 4 | + { glob = '', expected = '^$' }, |
| 5 | + { glob = 'abc', expected = '^abc$' }, |
| 6 | + { glob = 'ab#/.', expected = '^ab%#%/%.$' }, |
| 7 | + { glob = '\\\\\\ab\\c\\', expected = '^%\\abc\\$' }, |
| 8 | + |
| 9 | + { glob = 'abc.*', expected = '^abc%..*$', matches = { 'abc.txt', 'abc.' }, not_matches = { 'abc' } }, |
| 10 | + { glob = '??.txt', expected = '^..%.txt$' }, |
| 11 | + |
| 12 | + { glob = 'a[]', expected = '[^]' }, |
| 13 | + { glob = 'a[^]b', expected = '^ab$' }, |
| 14 | + { glob = 'a[!]b', expected = '^ab$' }, |
| 15 | + { glob = 'a[a][b]z', expected = '^a[a][b]z$' }, |
| 16 | + { glob = 'a[a-f]z', expected = '^a[a-f]z$' }, |
| 17 | + { glob = 'a[a-f0-9]z', expected = '^a[a-f0-9]z$' }, |
| 18 | + { glob = 'a[a-f0-]z', expected = '^a[a-f0%-]z$' }, |
| 19 | + { glob = 'a[!a-f]z', expected = '^a[^a-f]z$' }, |
| 20 | + { glob = 'a[^a-f]z', expected = '^a[^a-f]z$' }, |
| 21 | + { glob = 'a[\\!\\^\\-z\\]]z', expected = '^a[%!%^%-z%]]z$' }, |
| 22 | + { glob = 'a[\\a-\\f]z', expected = '^a[a-f]z$' }, |
| 23 | + |
| 24 | + { glob = 'a[', expected = '[^]' }, |
| 25 | + { glob = 'a[a-', expected = '[^]' }, |
| 26 | + { glob = 'a[a-b', expected = '[^]' }, |
| 27 | + { glob = 'a[!', expected = '[^]' }, |
| 28 | + { glob = 'a[!a', expected = '[^]' }, |
| 29 | + { glob = 'a[!a-', expected = '[^]' }, |
| 30 | + { glob = 'a[!a-b', expected = '[^]' }, |
| 31 | + { glob = 'a[!a-b\\]', expected = '[^]' }, |
| 32 | +} |
| 33 | + |
| 34 | +for _, case in ipairs(cases) do |
| 35 | + T['glob_to_pattern: ' .. case.glob] = function() |
| 36 | + local utils = require('CopilotChat.utils') |
| 37 | + local pattern = utils.glob_to_pattern(case.glob) |
| 38 | + MiniTest.expect.equality(pattern, case.expected) |
| 39 | + if case.matches then |
| 40 | + for _, str in ipairs(case.matches) do |
| 41 | + MiniTest.expect.equality(str:match(pattern) ~= nil, true) |
| 42 | + end |
| 43 | + end |
| 44 | + if case.not_matches then |
| 45 | + for _, str in ipairs(case.not_matches) do |
| 46 | + MiniTest.expect.equality(str:match(pattern) ~= nil, false) |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | +end |
| 51 | + |
| 52 | +return T |
0 commit comments