|
| 1 | +local t = require("TestKit") |
| 2 | +local Suggestions = require("apps.adventure-arena.zilscript.zilscript.reader.Suggestions") |
| 3 | + |
| 4 | +local key = { target = "brass key", noun = "key", aliases = { "key", "passkey" } } |
| 5 | +local door = { target = "oak door", noun = "door", aliases = { "door" } } |
| 6 | +local function complete(input, items) |
| 7 | + return Suggestions.forInput(input, items, function(offer) |
| 8 | + offer("unlock", door, "with", key) |
| 9 | + offer("put", key, "in", door) |
| 10 | + end) |
| 11 | +end |
| 12 | +local function has(input, items, title, text) |
| 13 | + for _, choice in ipairs(complete(input, items)) do |
| 14 | + if choice.title == title and choice.text == text then return true end |
| 15 | + end |
| 16 | + return false |
| 17 | +end |
| 18 | + |
| 19 | +t.expect(has("put passkey ", { key, door }, "in", "put passkey in "), |
| 20 | + "an object's parser synonym continues to the preposition") |
| 21 | +t.expect(has("put passkey in ", { key, door }, "door", "put passkey in door "), |
| 22 | + "a synonym preserves the typed command while completing its second object") |
| 23 | +t.expect(has("unlock door with ", { key, door }, "key", "unlock door with key "), |
| 24 | + "a normal noun still reaches the second object") |
| 25 | +local other = { target = "iron key", noun = "key", aliases = { "key", "passkey" } } |
| 26 | +t.expect(not has("put passkey ", { key, door, other }, "in", "put passkey in "), |
| 27 | + "an ambiguous synonym does not advance as if it identified one object") |
| 28 | +os.exit(t.summary() and 0 or 1) |
0 commit comments