mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 05:33:00 +00:00 
			
		
		
		
	Some cleanup to argument checking
- Consult __name in native code too. Closes #1355. This has the added advantage that unconvertable values (i.e. functions) will now correctly be reported as their original type, not just nil. - Fix the error message in cc.expect, so it matches the rest of Lua. This has been bugging me for years, and I keep forgetting to change it.
This commit is contained in:
		| @@ -39,6 +39,20 @@ public interface IArguments { | ||||
|     @Nullable | ||||
|     Object get(int index); | ||||
| 
 | ||||
|     /** | ||||
|      * Get the type name of the argument at the specific index. | ||||
|      * <p> | ||||
|      * This method is meant to be used in error reporting (namely with {@link LuaValues#badArgumentOf(IArguments, int, String)}), | ||||
|      * and should not be used to determine the actual type of an argument. | ||||
|      * | ||||
|      * @param index The argument number. | ||||
|      * @return The name of this type. | ||||
|      * @see LuaValues#getType(Object) | ||||
|      */ | ||||
|     default String getType(int index) { | ||||
|         return LuaValues.getType(get(index)); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Drop a number of arguments. The returned arguments instance will access arguments at position {@code i + count}, | ||||
|      * rather than {@code i}. However, errors will still use the given argument index. | ||||
| @@ -64,7 +78,7 @@ public interface IArguments { | ||||
|      */ | ||||
|     default double getDouble(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(index, "number", value); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(this, index, "number"); | ||||
|         return number.doubleValue(); | ||||
|     } | ||||
| 
 | ||||
| @@ -88,7 +102,7 @@ public interface IArguments { | ||||
|      */ | ||||
|     default long getLong(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(index, "number", value); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(this, index, "number"); | ||||
|         return LuaValues.checkFiniteNum(index, number).longValue(); | ||||
|     } | ||||
| 
 | ||||
| @@ -112,7 +126,7 @@ public interface IArguments { | ||||
|      */ | ||||
|     default boolean getBoolean(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (!(value instanceof Boolean bool)) throw LuaValues.badArgumentOf(index, "boolean", value); | ||||
|         if (!(value instanceof Boolean bool)) throw LuaValues.badArgumentOf(this, index, "boolean"); | ||||
|         return bool; | ||||
|     } | ||||
| 
 | ||||
| @@ -125,7 +139,7 @@ public interface IArguments { | ||||
|      */ | ||||
|     default String getString(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (!(value instanceof String string)) throw LuaValues.badArgumentOf(index, "string", value); | ||||
|         if (!(value instanceof String string)) throw LuaValues.badArgumentOf(this, index, "string"); | ||||
|         return string; | ||||
|     } | ||||
| 
 | ||||
| @@ -162,7 +176,7 @@ public interface IArguments { | ||||
|      */ | ||||
|     default Map<?, ?> getTable(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (!(value instanceof Map)) throw LuaValues.badArgumentOf(index, "table", value); | ||||
|         if (!(value instanceof Map)) throw LuaValues.badArgumentOf(this, index, "table"); | ||||
|         return (Map<?, ?>) value; | ||||
|     } | ||||
| 
 | ||||
| @@ -192,7 +206,7 @@ public interface IArguments { | ||||
|     default Optional<Double> optDouble(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (value == null) return Optional.empty(); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(index, "number", value); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(this, index, "number"); | ||||
|         return Optional.of(number.doubleValue()); | ||||
|     } | ||||
| 
 | ||||
| @@ -217,7 +231,7 @@ public interface IArguments { | ||||
|     default Optional<Long> optLong(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (value == null) return Optional.empty(); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(index, "number", value); | ||||
|         if (!(value instanceof Number number)) throw LuaValues.badArgumentOf(this, index, "number"); | ||||
|         return Optional.of(LuaValues.checkFiniteNum(index, number).longValue()); | ||||
|     } | ||||
| 
 | ||||
| @@ -244,7 +258,7 @@ public interface IArguments { | ||||
|     default Optional<Boolean> optBoolean(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (value == null) return Optional.empty(); | ||||
|         if (!(value instanceof Boolean bool)) throw LuaValues.badArgumentOf(index, "boolean", value); | ||||
|         if (!(value instanceof Boolean bool)) throw LuaValues.badArgumentOf(this, index, "boolean"); | ||||
|         return Optional.of(bool); | ||||
|     } | ||||
| 
 | ||||
| @@ -258,7 +272,7 @@ public interface IArguments { | ||||
|     default Optional<String> optString(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (value == null) return Optional.empty(); | ||||
|         if (!(value instanceof String string)) throw LuaValues.badArgumentOf(index, "string", value); | ||||
|         if (!(value instanceof String string)) throw LuaValues.badArgumentOf(this, index, "string"); | ||||
|         return Optional.of(string); | ||||
|     } | ||||
| 
 | ||||
| @@ -297,7 +311,7 @@ public interface IArguments { | ||||
|     default Optional<Map<?, ?>> optTable(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (value == null) return Optional.empty(); | ||||
|         if (!(value instanceof Map)) throw LuaValues.badArgumentOf(index, "map", value); | ||||
|         if (!(value instanceof Map)) throw LuaValues.badArgumentOf(this, index, "map"); | ||||
|         return Optional.of((Map<?, ?>) value); | ||||
|     } | ||||
| 
 | ||||
| @@ -316,7 +330,7 @@ public interface IArguments { | ||||
|     default Optional<LuaTable<?, ?>> optTableUnsafe(int index) throws LuaException { | ||||
|         var value = get(index); | ||||
|         if (value == null) return Optional.empty(); | ||||
|         if (!(value instanceof Map)) throw LuaValues.badArgumentOf(index, "map", value); | ||||
|         if (!(value instanceof Map)) throw LuaValues.badArgumentOf(this, index, "map"); | ||||
|         return Optional.of(new ObjectLuaTable((Map<?, ?>) value)); | ||||
|     } | ||||
| 
 | ||||
|   | ||||
| @@ -64,15 +64,15 @@ public final class LuaValues { | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Construct a "bad argument" exception, from an expected type and the actual value provided. | ||||
|      * Construct a "bad argument" exception, from an {@link IArguments} argument and an expected type. | ||||
|      * | ||||
|      * @param index    The argument number, starting from 0. | ||||
|      * @param expected The expected type for this argument. | ||||
|      * @param actual   The actual value provided for this argument. | ||||
|      * @param arguments The current arguments. | ||||
|      * @param index     The argument number, starting from 0. | ||||
|      * @param expected  The expected type for this argument. | ||||
|      * @return The constructed exception, which should be thrown immediately. | ||||
|      */ | ||||
|     public static LuaException badArgumentOf(int index, String expected, @Nullable Object actual) { | ||||
|         return badArgument(index, expected, getType(actual)); | ||||
|     public static LuaException badArgumentOf(IArguments arguments, int index, String expected) { | ||||
|         return badArgument(index, expected, arguments.getType(index)); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|   | ||||
| @@ -60,7 +60,7 @@ public class BinaryWritableHandle extends HandleGeneric { | ||||
|             } else if (arg instanceof String) { | ||||
|                 channel.write(arguments.getBytes(0)); | ||||
|             } else { | ||||
|                 throw LuaValues.badArgumentOf(0, "string or number", arg); | ||||
|                 throw LuaValues.badArgumentOf(arguments, 0, "string or number"); | ||||
|             } | ||||
|         } catch (IOException e) { | ||||
|             throw new LuaException(e.getMessage()); | ||||
|   | ||||
| @@ -13,6 +13,8 @@ import javax.annotation.Nullable; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.util.Optional; | ||||
| 
 | ||||
| import static org.squiddev.cobalt.Constants.NAME; | ||||
| 
 | ||||
| final class VarargArguments implements IArguments { | ||||
|     private static final VarargArguments EMPTY = new VarargArguments(Constants.NONE); | ||||
| 
 | ||||
| @@ -49,6 +51,17 @@ final class VarargArguments implements IArguments { | ||||
|         return cache[index] = CobaltLuaMachine.toObject(varargs.arg(index + 1), null); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getType(int index) { | ||||
|         var value = varargs.arg(index + 1); | ||||
|         if (value instanceof LuaTable || value instanceof LuaUserdata) { | ||||
|             var metatable = value.getMetatable(null); | ||||
|             if (metatable != null && metatable.rawget(NAME) instanceof LuaString s) return s.toString(); | ||||
|         } | ||||
| 
 | ||||
|         return value.typeName(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public IArguments drop(int count) { | ||||
|         if (count < 0) throw new IllegalStateException("count cannot be negative"); | ||||
|   | ||||
| @@ -20,7 +20,7 @@ placed within a disk drive to access it's internal storage like a disk. | ||||
|  | ||||
| local function isDrive(name) | ||||
|     if type(name) ~= "string" then | ||||
|         error("bad argument #1 (expected string, got " .. type(name) .. ")", 3) | ||||
|         error("bad argument #1 (string expected, got " .. type(name) .. ")", 3) | ||||
|     end | ||||
|     return peripheral.getType(name) == "drive" | ||||
| end | ||||
|   | ||||
| @@ -25,7 +25,7 @@ local function checkKey(options, key, ty, opt) | ||||
|     local valueTy = type(value) | ||||
|  | ||||
|     if (value ~= nil or not opt) and valueTy ~= ty then | ||||
|         error(("bad field '%s' (expected %s, got %s"):format(key, ty, valueTy), 4) | ||||
|         error(("bad field '%s' (%s expected, got %s"):format(key, ty, valueTy), 4) | ||||
|     end | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -157,7 +157,7 @@ handleMetatable = { | ||||
|                         error("bad argument #" .. i .. " (invalid format)", 2) | ||||
|                     end | ||||
|                 else | ||||
|                     error("bad argument #" .. i .. " (expected string, got " .. type_of(arg) .. ")", 2) | ||||
|                     error("bad argument #" .. i .. " (string expected, got " .. type_of(arg) .. ")", 2) | ||||
|                 end | ||||
|  | ||||
|                 output[i] = res | ||||
|   | ||||
| @@ -47,7 +47,7 @@ local function create(...) | ||||
|     for i = 1, tFns.n, 1 do | ||||
|         local fn = tFns[i] | ||||
|         if type(fn) ~= "function" then | ||||
|             error("bad argument #" .. i .. " (expected function, got " .. type(fn) .. ")", 3) | ||||
|             error("bad argument #" .. i .. " (function expected, got " .. type(fn) .. ")", 3) | ||||
|         end | ||||
|  | ||||
|         tCos[i] = coroutine.create(fn) | ||||
|   | ||||
| @@ -181,7 +181,7 @@ local function tabulateCommon(bPaged, ...) | ||||
|             for nu, sItem in pairs(t) do | ||||
|                 local ty = type(sItem) | ||||
|                 if ty ~= "string" and ty ~= "number" then | ||||
|                     error("bad argument #" .. n .. "." .. nu .. " (expected string, got " .. ty .. ")", 3) | ||||
|                     error("bad argument #" .. n .. "." .. nu .. " (string expected, got " .. ty .. ")", 3) | ||||
|                 end | ||||
|                 nMaxLen = math.max(#tostring(sItem) + 1, nMaxLen) | ||||
|             end | ||||
|   | ||||
| @@ -79,9 +79,9 @@ local function expect(index, value, ...) | ||||
|  | ||||
|     local type_names = get_type_names(...) | ||||
|     if name then | ||||
|         error(("bad argument #%d to '%s' (expected %s, got %s)"):format(index, name, type_names, t), 3) | ||||
|         error(("bad argument #%d to '%s' (%s expected, got %s)"):format(index, name, type_names, t), 3) | ||||
|     else | ||||
|         error(("bad argument #%d (expected %s, got %s)"):format(index, type_names, t), 3) | ||||
|         error(("bad argument #%d (%s expected, got %s)"):format(index, type_names, t), 3) | ||||
|     end | ||||
| end | ||||
|  | ||||
| @@ -107,7 +107,7 @@ local function field(tbl, index, ...) | ||||
|     if value == nil then | ||||
|         error(("field '%s' missing from table"):format(index), 3) | ||||
|     else | ||||
|         error(("bad field '%s' (expected %s, got %s)"):format(index, get_type_names(...), t), 3) | ||||
|         error(("bad field '%s' (%s expected, got %s)"):format(index, get_type_names(...), t), 3) | ||||
|     end | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -167,7 +167,7 @@ local function build(...) | ||||
|             end | ||||
|  | ||||
|             if type(arg[1]) ~= "function" then | ||||
|                 error(("Bad table entry #1 at argument #%d (expected function, got %s)"):format(i, type(arg[1])), 2) | ||||
|                 error(("Bad table entry #1 at argument #%d (function expected, got %s)"):format(i, type(arg[1])), 2) | ||||
|             end | ||||
|  | ||||
|             if arg.many and i < arguments.n then | ||||
|   | ||||
| @@ -27,7 +27,7 @@ local function check(func, idx, ty, val) | ||||
|             error(('%s: bad argument #%d (got nil)'):format(func, idx), 3) | ||||
|         end | ||||
|     elseif type(val) ~= ty then | ||||
|         return error(('%s: bad argument #%d (expected %s, got %s)'):format(func, idx, ty, type(val)), 3) | ||||
|         return error(('%s: bad argument #%d (%s expected, got %s)'):format(func, idx, ty, type(val)), 3) | ||||
|     end | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| describe("The colors library", function() | ||||
|     describe("colors.combine", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(colors.combine, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(colors.combine, 1, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(colors.combine, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(colors.combine, 1, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("combines colours", function() | ||||
| @@ -17,9 +17,9 @@ describe("The colors library", function() | ||||
|  | ||||
|     describe("colors.subtract", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(colors.subtract, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(colors.subtract, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(colors.subtract, 1, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(colors.subtract, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(colors.subtract, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(colors.subtract, 1, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("subtracts colours", function() | ||||
| @@ -36,8 +36,8 @@ describe("The colors library", function() | ||||
|  | ||||
|     describe("colors.test", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(colors.test, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(colors.test, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(colors.test, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(colors.test, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("returns true when present", function() | ||||
| @@ -53,9 +53,9 @@ describe("The colors library", function() | ||||
|  | ||||
|     describe("colors.packRGB", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(colors.packRGB, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(colors.packRGB, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(colors.packRGB, 1, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(colors.packRGB, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(colors.packRGB, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(colors.packRGB, 1, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("packs colours", function() | ||||
| @@ -65,7 +65,7 @@ describe("The colors library", function() | ||||
|  | ||||
|     describe("colors.unpackRGB", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(colors.unpackRGB, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(colors.unpackRGB, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("unpacks colours", function() | ||||
| @@ -80,7 +80,7 @@ describe("The colors library", function() | ||||
|  | ||||
|     describe("colors.toBlit", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(colors.toBlit, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(colors.toBlit, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("converts all colors", function() | ||||
|   | ||||
| @@ -13,10 +13,10 @@ describe("The fs library", function() | ||||
|             fs.complete("", "", true) | ||||
|             fs.complete("", "", nil, true) | ||||
|  | ||||
|             expect.error(fs.complete, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(fs.complete, "", nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(fs.complete, "", "", 1):eq("bad argument #3 (expected boolean, got number)") | ||||
|             expect.error(fs.complete, "", "", true, 1):eq("bad argument #4 (expected boolean, got number)") | ||||
|             expect.error(fs.complete, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(fs.complete, "", nil):eq("bad argument #2 (string expected, got nil)") | ||||
|             expect.error(fs.complete, "", "", 1):eq("bad argument #3 (boolean expected, got number)") | ||||
|             expect.error(fs.complete, "", "", true, 1):eq("bad argument #4 (boolean expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         describe("include_hidden", function() | ||||
| @@ -64,7 +64,7 @@ describe("The fs library", function() | ||||
|         it("validates arguments", function() | ||||
|             fs.isDriveRoot("") | ||||
|  | ||||
|             expect.error(fs.isDriveRoot, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(fs.isDriveRoot, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("correctly identifies drive roots", function() | ||||
|   | ||||
| @@ -12,8 +12,8 @@ describe("The gps library", function() | ||||
|             gps.locate(1) | ||||
|             gps.locate(1, true) | ||||
|  | ||||
|             expect.error(gps.locate, ""):eq("bad argument #1 (expected number, got string)") | ||||
|             expect.error(gps.locate, 1, ""):eq("bad argument #2 (expected boolean, got string)") | ||||
|             expect.error(gps.locate, ""):eq("bad argument #1 (number expected, got string)") | ||||
|             expect.error(gps.locate, 1, ""):eq("bad argument #2 (boolean expected, got string)") | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
|   | ||||
| @@ -6,21 +6,21 @@ describe("The help library", function() | ||||
|     describe("help.setPath", function() | ||||
|         it("validates arguments", function() | ||||
|             help.setPath(help.path()) | ||||
|             expect.error(help.setPath, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(help.setPath, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("help.lookup", function() | ||||
|         it("validates arguments", function() | ||||
|             help.lookup("") | ||||
|             expect.error(help.lookup, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(help.lookup, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("help.completeTopic", function() | ||||
|         it("validates arguments", function() | ||||
|             help.completeTopic("") | ||||
|             expect.error(help.completeTopic, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(help.completeTopic, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("completes topics without extensions", function() | ||||
|   | ||||
| @@ -76,7 +76,7 @@ describe("The io library", function() | ||||
|         it("validates arguments", function() | ||||
|             io.lines(nil) | ||||
|             expect.error(io.lines, ""):eq("/: No such file") | ||||
|             expect.error(io.lines, false):eq("bad argument #1 (expected string, got boolean)") | ||||
|             expect.error(io.lines, false):eq("bad argument #1 (string expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("closes the file", function() | ||||
| @@ -167,8 +167,8 @@ describe("The io library", function() | ||||
|             io.open("") | ||||
|             io.open("", "r") | ||||
|  | ||||
|             expect.error(io.open, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(io.open, "", false):eq("bad argument #2 (expected string, got boolean)") | ||||
|             expect.error(io.open, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(io.open, "", false):eq("bad argument #2 (string expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("checks the mode", function() | ||||
|   | ||||
| @@ -6,7 +6,7 @@ describe("The keys library", function() | ||||
|     describe("keys.getName", function() | ||||
|         it("validates arguments", function() | ||||
|             keys.getName(1) | ||||
|             expect.error(keys.getName, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(keys.getName, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
|   | ||||
| @@ -179,13 +179,13 @@ describe("The os library", function() | ||||
|  | ||||
|     describe("os.loadAPI", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(os.loadAPI, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(os.loadAPI, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("os.unloadAPI", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(os.loadAPI, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(os.loadAPI, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
|   | ||||
| @@ -21,31 +21,31 @@ describe("The paintutils library", function() | ||||
|     describe("paintutils.parseImage", function() | ||||
|         it("validates arguments", function() | ||||
|             paintutils.parseImage("") | ||||
|             expect.error(paintutils.parseImage, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(paintutils.parseImage, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("paintutils.loadImage", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(paintutils.loadImage, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(paintutils.loadImage, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("paintutils.drawPixel", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(paintutils.drawPixel, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawPixel, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawPixel, 1, 1, false):eq("bad argument #3 (expected number, got boolean)") | ||||
|             expect.error(paintutils.drawPixel, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawPixel, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawPixel, 1, 1, false):eq("bad argument #3 (number expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("paintutils.drawLine", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(paintutils.drawLine, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, 1, 1, nil):eq("bad argument #4 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, 1, 1, 1, false):eq("bad argument #5 (expected number, got boolean)") | ||||
|             expect.error(paintutils.drawLine, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, 1, 1, nil):eq("bad argument #4 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawLine, 1, 1, 1, 1, false):eq("bad argument #5 (number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("draws a line going across with custom colour", function() | ||||
| @@ -88,11 +88,11 @@ describe("The paintutils library", function() | ||||
|  | ||||
|     describe("paintutils.drawBox", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(paintutils.drawBox, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, 1, 1, nil):eq("bad argument #4 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, 1, 1, 1, false):eq("bad argument #5 (expected number, got boolean)") | ||||
|             expect.error(paintutils.drawBox, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, 1, 1, nil):eq("bad argument #4 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawBox, 1, 1, 1, 1, false):eq("bad argument #5 (number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("draws a box with term colour", function() | ||||
| @@ -137,11 +137,11 @@ describe("The paintutils library", function() | ||||
|  | ||||
|     describe("paintutils.drawFilledBox", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(paintutils.drawFilledBox, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, 1, 1, nil):eq("bad argument #4 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, 1, 1, 1, false):eq("bad argument #5 (expected number, got boolean)") | ||||
|             expect.error(paintutils.drawFilledBox, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, 1, 1, nil):eq("bad argument #4 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawFilledBox, 1, 1, 1, 1, false):eq("bad argument #5 (number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("draws a filled box with term colour", function() | ||||
| @@ -172,9 +172,9 @@ describe("The paintutils library", function() | ||||
|  | ||||
|     describe("paintutils.drawImage", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(paintutils.drawImage, nil):eq("bad argument #1 (expected table, got nil)") | ||||
|             expect.error(paintutils.drawImage, {}, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawImage, {}, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(paintutils.drawImage, nil):eq("bad argument #1 (table expected, got nil)") | ||||
|             expect.error(paintutils.drawImage, {}, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(paintutils.drawImage, {}, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| describe("The parallel library", function() | ||||
|     describe("parallel.waitForAny", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(parallel.waitForAny, ""):eq("bad argument #1 (expected function, got string)") | ||||
|             expect.error(parallel.waitForAny, function() end, 2):eq("bad argument #2 (expected function, got number)") | ||||
|             expect.error(parallel.waitForAny, ""):eq("bad argument #1 (function expected, got string)") | ||||
|             expect.error(parallel.waitForAny, function() end, 2):eq("bad argument #2 (function expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("returns immediately with no arguments", function() | ||||
| @@ -66,8 +66,8 @@ describe("The parallel library", function() | ||||
|  | ||||
|     describe("parallel.waitForAll", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(parallel.waitForAll, ""):eq("bad argument #1 (expected function, got string)") | ||||
|             expect.error(parallel.waitForAll, function() end, 2):eq("bad argument #2 (expected function, got number)") | ||||
|             expect.error(parallel.waitForAll, ""):eq("bad argument #1 (function expected, got string)") | ||||
|             expect.error(parallel.waitForAll, function() end, 2):eq("bad argument #2 (function expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("returns immediately with no arguments", function() | ||||
|   | ||||
| @@ -16,7 +16,7 @@ describe("The peripheral library", function() | ||||
|     describe("peripheral.isPresent", function() | ||||
|         it("validates arguments", function() | ||||
|             peripheral.isPresent("") | ||||
|             expect.error(peripheral.isPresent, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(peripheral.isPresent, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it_modem("asserts the presence of local peripherals", function() | ||||
| @@ -32,7 +32,7 @@ describe("The peripheral library", function() | ||||
|  | ||||
|     describe("peripheral.getName", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(peripheral.getName, nil):eq("bad argument #1 (expected table, got nil)") | ||||
|             expect.error(peripheral.getName, nil):eq("bad argument #1 (table expected, got nil)") | ||||
|             expect.error(peripheral.getName, {}):eq("bad argument #1 (table is not a peripheral)") | ||||
|         end) | ||||
|  | ||||
| @@ -48,7 +48,7 @@ describe("The peripheral library", function() | ||||
|     describe("peripheral.getType", function() | ||||
|         it("validates arguments", function() | ||||
|             peripheral.getType("") | ||||
|             expect.error(peripheral.getType, nil):eq("bad argument #1 (expected string or table, got nil)") | ||||
|             expect.error(peripheral.getType, nil):eq("bad argument #1 (string or table expected, got nil)") | ||||
|             expect.error(peripheral.getType, {}):eq("bad argument #1 (table is not a peripheral)") | ||||
|         end) | ||||
|  | ||||
| @@ -77,9 +77,9 @@ describe("The peripheral library", function() | ||||
|     describe("peripheral.hasType", function() | ||||
|         it("validates arguments", function() | ||||
|             peripheral.getType("") | ||||
|             expect.error(peripheral.hasType, nil):eq("bad argument #1 (expected string or table, got nil)") | ||||
|             expect.error(peripheral.hasType, nil):eq("bad argument #1 (string or table expected, got nil)") | ||||
|             expect.error(peripheral.hasType, {}, ""):eq("bad argument #1 (table is not a peripheral)") | ||||
|             expect.error(peripheral.hasType, ""):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(peripheral.hasType, ""):eq("bad argument #2 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("returns nil when no peripherals are present", function() | ||||
| @@ -110,15 +110,15 @@ describe("The peripheral library", function() | ||||
|     describe("peripheral.getMethods", function() | ||||
|         it("validates arguments", function() | ||||
|             peripheral.getMethods("") | ||||
|             expect.error(peripheral.getMethods, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(peripheral.getMethods, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("peripheral.call", function() | ||||
|         it("validates arguments", function() | ||||
|             peripheral.call("", "") | ||||
|             expect.error(peripheral.call, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(peripheral.call, "", nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(peripheral.call, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(peripheral.call, "", nil):eq("bad argument #2 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it_modem("has the correct error location", function() | ||||
| @@ -130,7 +130,7 @@ describe("The peripheral library", function() | ||||
|     describe("peripheral.wrap", function() | ||||
|         it("validates arguments", function() | ||||
|             peripheral.wrap("") | ||||
|             expect.error(peripheral.wrap, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(peripheral.wrap, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it_modem("wraps a local peripheral", function() | ||||
| @@ -151,8 +151,8 @@ describe("The peripheral library", function() | ||||
|             peripheral.find("") | ||||
|             peripheral.find("", function() | ||||
|             end) | ||||
|             expect.error(peripheral.find, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(peripheral.find, "", false):eq("bad argument #2 (expected function, got boolean)") | ||||
|             expect.error(peripheral.find, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(peripheral.find, "", false):eq("bad argument #2 (function expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it_modem("finds a local peripheral", function() | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
| describe("The rednet library", function() | ||||
|     describe("rednet.open", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(rednet.open, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(rednet.open, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("requires a modem to be present", function() | ||||
| @@ -16,8 +16,8 @@ describe("The rednet library", function() | ||||
|     describe("rednet.close", function() | ||||
|         it("validates arguments", function() | ||||
|             rednet.close() | ||||
|             expect.error(rednet.close, 1):eq("bad argument #1 (expected string, got number)") | ||||
|             expect.error(rednet.close, false):eq("bad argument #1 (expected string, got boolean)") | ||||
|             expect.error(rednet.close, 1):eq("bad argument #1 (string expected, got number)") | ||||
|             expect.error(rednet.close, false):eq("bad argument #1 (string expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("requires a modem to be present", function() | ||||
| @@ -29,8 +29,8 @@ describe("The rednet library", function() | ||||
|         it("validates arguments", function() | ||||
|             rednet.isOpen() | ||||
|             rednet.isOpen("") | ||||
|             expect.error(rednet.isOpen, 1):eq("bad argument #1 (expected string, got number)") | ||||
|             expect.error(rednet.isOpen, false):eq("bad argument #1 (expected string, got boolean)") | ||||
|             expect.error(rednet.isOpen, 1):eq("bad argument #1 (string expected, got number)") | ||||
|             expect.error(rednet.isOpen, false):eq("bad argument #1 (string expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -38,8 +38,8 @@ describe("The rednet library", function() | ||||
|         it("validates arguments", function() | ||||
|             rednet.send(1) | ||||
|             rednet.send(1, nil, "") | ||||
|             expect.error(rednet.send, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(rednet.send, 1, nil, false):eq("bad argument #3 (expected string, got boolean)") | ||||
|             expect.error(rednet.send, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(rednet.send, 1, nil, false):eq("bad argument #3 (string expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("queues an event on the current computer", function() | ||||
| @@ -55,36 +55,36 @@ describe("The rednet library", function() | ||||
|         it("validates arguments", function() | ||||
|             rednet.broadcast(nil) | ||||
|             rednet.broadcast(nil, "") | ||||
|             expect.error(rednet.broadcast, nil, false):eq("bad argument #2 (expected string, got boolean)") | ||||
|             expect.error(rednet.broadcast, nil, false):eq("bad argument #2 (string expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("rednet.receive", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(rednet.receive, false):eq("bad argument #1 (expected string, got boolean)") | ||||
|             expect.error(rednet.receive, "", false):eq("bad argument #2 (expected number, got boolean)") | ||||
|             expect.error(rednet.receive, false):eq("bad argument #1 (string expected, got boolean)") | ||||
|             expect.error(rednet.receive, "", false):eq("bad argument #2 (number expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("rednet.host", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(rednet.host, "", "localhost"):eq("Reserved hostname") | ||||
|             expect.error(rednet.host, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(rednet.host, "", nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(rednet.host, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(rednet.host, "", nil):eq("bad argument #2 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("rednet.unhost", function() | ||||
|         it("validates arguments", function() | ||||
|             rednet.unhost("") | ||||
|             expect.error(rednet.unhost, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(rednet.unhost, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("rednet.lookup", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(rednet.lookup, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(rednet.lookup, "", false):eq("bad argument #2 (expected string, got boolean)") | ||||
|             expect.error(rednet.lookup, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(rednet.lookup, "", false):eq("bad argument #2 (string expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("gets a locally hosted protocol", function() | ||||
|   | ||||
| @@ -24,8 +24,8 @@ describe("The settings library", function() | ||||
|             settings.set("test", {}) | ||||
|             settings.set("test", false) | ||||
|  | ||||
|             expect.error(settings.set, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(settings.set, "", nil):eq("bad argument #2 (expected number, string, boolean or table, got nil)") | ||||
|             expect.error(settings.set, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(settings.set, "", nil):eq("bad argument #2 (number, string, boolean or table expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("prevents storing unserialisable types", function() | ||||
| @@ -41,7 +41,7 @@ describe("The settings library", function() | ||||
|         it("checks the type of the value", function() | ||||
|             settings.define("test.defined", { default = 123, description = "A description", type = "number" }) | ||||
|             expect.error(settings.set, "test.defined", "hello") | ||||
|                 :eq("bad argument #2 (expected number, got string)") | ||||
|                 :eq("bad argument #2 (number expected, got string)") | ||||
|             settings.set("test.defined", 123) | ||||
|         end) | ||||
|  | ||||
| @@ -60,7 +60,7 @@ describe("The settings library", function() | ||||
|     describe("settings.get", function() | ||||
|         it("validates arguments", function() | ||||
|             settings.get("test") | ||||
|             expect.error(settings.get, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(settings.get, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("returns the default", function() | ||||
| @@ -75,7 +75,7 @@ describe("The settings library", function() | ||||
|  | ||||
|     describe("settings.getDetails", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(settings.getDetails, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(settings.getDetails, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("works on undefined and unset values", function() | ||||
| @@ -104,7 +104,7 @@ describe("The settings library", function() | ||||
|     describe("settings.unset", function() | ||||
|         it("validates arguments", function() | ||||
|             settings.unset("test") | ||||
|             expect.error(settings.unset, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(settings.unset, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("unsetting resets the value", function() | ||||
| @@ -154,7 +154,7 @@ describe("The settings library", function() | ||||
|  | ||||
|     describe("settings.load", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(settings.load, 1):eq("bad argument #1 (expected string, got number)") | ||||
|             expect.error(settings.load, 1):eq("bad argument #1 (string expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         local function setup_with(contents) | ||||
| @@ -210,7 +210,7 @@ describe("The settings library", function() | ||||
|  | ||||
|     describe("settings.save", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(settings.save, 1):eq("bad argument #1 (expected string, got number)") | ||||
|             expect.error(settings.save, 1):eq("bad argument #1 (string expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("defaults to .settings", function() | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
| describe("The term library", function() | ||||
|     describe("term.redirect", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(term.redirect, nil):eq("bad argument #1 (expected table, got nil)") | ||||
|             expect.error(term.redirect, nil):eq("bad argument #1 (table expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("prevents redirecting to term", function() | ||||
|   | ||||
| @@ -7,7 +7,7 @@ local helpers = require "test_helpers" | ||||
| describe("The textutils library", function() | ||||
|     describe("textutils.slowWrite", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(textutils.slowWrite, nil, false):eq("bad argument #2 (expected number, got boolean)") | ||||
|             expect.error(textutils.slowWrite, nil, false):eq("bad argument #2 (number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("wraps text correctly", function() | ||||
| @@ -28,8 +28,8 @@ describe("The textutils library", function() | ||||
|         it("validates arguments", function() | ||||
|             textutils.formatTime(0) | ||||
|             textutils.formatTime(0, false) | ||||
|             expect.error(textutils.formatTime, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(textutils.formatTime, 1, 1):eq("bad argument #2 (expected boolean, got number)") | ||||
|             expect.error(textutils.formatTime, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(textutils.formatTime, 1, 1):eq("bad argument #2 (boolean expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("correctly formats 12 o'clock", function() | ||||
| @@ -43,7 +43,7 @@ describe("The textutils library", function() | ||||
|  | ||||
|     describe("textutils.pagedPrint", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(textutils.pagedPrint, nil, false):eq("bad argument #2 (expected number, got boolean)") | ||||
|             expect.error(textutils.pagedPrint, nil, false):eq("bad argument #2 (number expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -55,9 +55,9 @@ describe("The textutils library", function() | ||||
|             textutils.tabulate({ "test", 1 }) | ||||
|             textutils.tabulate(colors.white) | ||||
|  | ||||
|             expect.error(textutils.tabulate, nil):eq("bad argument #1 (expected number or table, got nil)") | ||||
|             expect.error(textutils.tabulate, { "test" }, nil):eq("bad argument #2 (expected number or table, got nil)") | ||||
|             expect.error(textutils.tabulate, { false }):eq("bad argument #1.1 (expected string, got boolean)") | ||||
|             expect.error(textutils.tabulate, nil):eq("bad argument #1 (number or table expected, got nil)") | ||||
|             expect.error(textutils.tabulate, { "test" }, nil):eq("bad argument #2 (number or table expected, got nil)") | ||||
|             expect.error(textutils.tabulate, { false }):eq("bad argument #1.1 (string expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -69,8 +69,8 @@ describe("The textutils library", function() | ||||
|             textutils.pagedTabulate({ "test" }) | ||||
|             textutils.pagedTabulate(colors.white) | ||||
|  | ||||
|             expect.error(textutils.pagedTabulate, nil):eq("bad argument #1 (expected number or table, got nil)") | ||||
|             expect.error(textutils.pagedTabulate, { "test" }, nil):eq("bad argument #2 (expected number or table, got nil)") | ||||
|             expect.error(textutils.pagedTabulate, nil):eq("bad argument #1 (number or table expected, got nil)") | ||||
|             expect.error(textutils.pagedTabulate, { "test" }, nil):eq("bad argument #2 (number or table expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -132,7 +132,7 @@ describe("The textutils library", function() | ||||
|     describe("textutils.unserialise", function() | ||||
|         it("validates arguments", function() | ||||
|             textutils.unserialise("") | ||||
|             expect.error(textutils.unserialise, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(textutils.unserialise, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -143,8 +143,8 @@ describe("The textutils library", function() | ||||
|             textutils.serialiseJSON({}) | ||||
|             textutils.serialiseJSON(false) | ||||
|             textutils.serialiseJSON("", true) | ||||
|             expect.error(textutils.serialiseJSON, nil):eq("bad argument #1 (expected table, string, number or boolean, got nil)") | ||||
|             expect.error(textutils.serialiseJSON, "", 1):eq("bad argument #2 (expected boolean, got number)") | ||||
|             expect.error(textutils.serialiseJSON, nil):eq("bad argument #1 (table, string, number or boolean expected, got nil)") | ||||
|             expect.error(textutils.serialiseJSON, "", 1):eq("bad argument #2 (boolean expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("serializes empty arrays", function() | ||||
| @@ -257,7 +257,7 @@ describe("The textutils library", function() | ||||
|     describe("textutils.urlEncode", function() | ||||
|         it("validates arguments", function() | ||||
|             textutils.urlEncode("") | ||||
|             expect.error(textutils.urlEncode, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(textutils.urlEncode, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -265,8 +265,8 @@ describe("The textutils library", function() | ||||
|         it("validates arguments", function() | ||||
|             textutils.complete("pri") | ||||
|             textutils.complete("pri", _G) | ||||
|             expect.error(textutils.complete, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(textutils.complete, "", false):eq("bad argument #2 (expected table, got boolean)") | ||||
|             expect.error(textutils.complete, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(textutils.complete, "", false):eq("bad argument #2 (table expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
|   | ||||
| @@ -13,12 +13,12 @@ describe("The window library", function() | ||||
|             window.create(r, 1, 1, 5, 5) | ||||
|             window.create(r, 1, 1, 5, 5, false) | ||||
|  | ||||
|             expect.error(window.create, nil):eq("bad argument #1 (expected table, got nil)") | ||||
|             expect.error(window.create, r, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(window.create, r, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(window.create, r, 1, 1, nil):eq("bad argument #4 (expected number, got nil)") | ||||
|             expect.error(window.create, r, 1, 1, 1, nil):eq("bad argument #5 (expected number, got nil)") | ||||
|             expect.error(window.create, r, 1, 1, 1, 1, ""):eq("bad argument #6 (expected boolean, got string)") | ||||
|             expect.error(window.create, nil):eq("bad argument #1 (table expected, got nil)") | ||||
|             expect.error(window.create, r, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(window.create, r, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(window.create, r, 1, 1, nil):eq("bad argument #4 (number expected, got nil)") | ||||
|             expect.error(window.create, r, 1, 1, 1, nil):eq("bad argument #5 (number expected, got nil)") | ||||
|             expect.error(window.create, r, 1, 1, 1, 1, ""):eq("bad argument #6 (boolean expected, got string)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -27,9 +27,9 @@ describe("The window library", function() | ||||
|             local w = mk() | ||||
|             w.blit("a", "a", "a") | ||||
|  | ||||
|             expect.error(w.blit, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(w.blit, "", nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(w.blit, "", "", nil):eq("bad argument #3 (expected string, got nil)") | ||||
|             expect.error(w.blit, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(w.blit, "", nil):eq("bad argument #2 (string expected, got nil)") | ||||
|             expect.error(w.blit, "", "", nil):eq("bad argument #3 (string expected, got nil)") | ||||
|             expect.error(w.blit, "", "", "a"):eq("Arguments must be the same length") | ||||
|         end) | ||||
|     end) | ||||
| @@ -39,8 +39,8 @@ describe("The window library", function() | ||||
|             local w = mk() | ||||
|             w.setCursorPos(1, 1) | ||||
|  | ||||
|             expect.error(w.setCursorPos, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.setCursorPos, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(w.setCursorPos, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.setCursorPos, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -48,7 +48,7 @@ describe("The window library", function() | ||||
|         it("validates arguments", function() | ||||
|             local w = mk() | ||||
|             w.setCursorBlink(false) | ||||
|             expect.error(w.setCursorBlink, nil):eq("bad argument #1 (expected boolean, got nil)") | ||||
|             expect.error(w.setCursorBlink, nil):eq("bad argument #1 (boolean expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -57,7 +57,7 @@ describe("The window library", function() | ||||
|             local w = mk() | ||||
|             w.setTextColour(colors.white) | ||||
|  | ||||
|             expect.error(w.setTextColour, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.setTextColour, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.setTextColour, -5):eq("Invalid color (got -5)") | ||||
|         end) | ||||
|     end) | ||||
| @@ -68,12 +68,12 @@ describe("The window library", function() | ||||
|             w.setPaletteColour(colors.white, 0, 0, 0) | ||||
|             w.setPaletteColour(colors.white, 0x000000) | ||||
|  | ||||
|             expect.error(w.setPaletteColour, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.setPaletteColour, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.setPaletteColour, -5):eq("Invalid color (got -5)") | ||||
|             expect.error(w.setPaletteColour, colors.white):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(w.setPaletteColour, colors.white, 1, false):eq("bad argument #3 (expected number, got boolean)") | ||||
|             expect.error(w.setPaletteColour, colors.white, 1, nil, 1):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(w.setPaletteColour, colors.white, 1, 1, nil):eq("bad argument #4 (expected number, got nil)") | ||||
|             expect.error(w.setPaletteColour, colors.white):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(w.setPaletteColour, colors.white, 1, false):eq("bad argument #3 (number expected, got boolean)") | ||||
|             expect.error(w.setPaletteColour, colors.white, 1, nil, 1):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(w.setPaletteColour, colors.white, 1, 1, nil):eq("bad argument #4 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -81,7 +81,7 @@ describe("The window library", function() | ||||
|         it("validates arguments", function() | ||||
|             local w = mk() | ||||
|             w.getPaletteColour(colors.white) | ||||
|             expect.error(w.getPaletteColour, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.getPaletteColour, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.getPaletteColour, -5):eq("Invalid color (got -5)") | ||||
|         end) | ||||
|     end) | ||||
| @@ -91,7 +91,7 @@ describe("The window library", function() | ||||
|             local w = mk() | ||||
|             w.setBackgroundColour(colors.white) | ||||
|  | ||||
|             expect.error(w.setBackgroundColour, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.setBackgroundColour, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.setBackgroundColour, -5):eq("Invalid color (got -5)") | ||||
|         end) | ||||
|     end) | ||||
| @@ -100,7 +100,7 @@ describe("The window library", function() | ||||
|         it("validates arguments", function() | ||||
|             local w = mk() | ||||
|             w.scroll(0) | ||||
|             expect.error(w.scroll, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.scroll, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -108,7 +108,7 @@ describe("The window library", function() | ||||
|         it("validates arguments", function() | ||||
|             local w = mk() | ||||
|             w.setVisible(false) | ||||
|             expect.error(w.setVisible, nil):eq("bad argument #1 (expected boolean, got nil)") | ||||
|             expect.error(w.setVisible, nil):eq("bad argument #1 (boolean expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -117,12 +117,12 @@ describe("The window library", function() | ||||
|             local w = mk() | ||||
|             w.reposition(1, 1) | ||||
|             w.reposition(1, 1, 5, 5) | ||||
|             expect.error(w.reposition, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.reposition, 1, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(w.reposition, 1, 1, false, 1):eq("bad argument #3 (expected number, got boolean)") | ||||
|             expect.error(w.reposition, 1, 1, nil, 1):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(w.reposition, 1, 1, 1, nil):eq("bad argument #4 (expected number, got nil)") | ||||
|             expect.error(w.reposition, 1, 1, 1, 1, true):eq("bad argument #5 (expected table, got boolean)") | ||||
|             expect.error(w.reposition, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.reposition, 1, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(w.reposition, 1, 1, false, 1):eq("bad argument #3 (number expected, got boolean)") | ||||
|             expect.error(w.reposition, 1, 1, nil, 1):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(w.reposition, 1, 1, 1, nil):eq("bad argument #4 (number expected, got nil)") | ||||
|             expect.error(w.reposition, 1, 1, 1, 1, true):eq("bad argument #5 (table expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("can change the buffer", function() | ||||
| @@ -150,7 +150,7 @@ describe("The window library", function() | ||||
|             local w = mk() | ||||
|             w.getLine(1) | ||||
|             local _, y = w.getSize() | ||||
|             expect.error(w.getLine, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(w.getLine, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.getLine, 0):eq("Line is out of range.") | ||||
|             expect.error(w.getLine, y + 1):eq("Line is out of range.") | ||||
|         end) | ||||
| @@ -164,7 +164,7 @@ describe("The window library", function() | ||||
|     describe("Window.setVisible", function() | ||||
|         it("validates arguments", function() | ||||
|             local w = mk() | ||||
|             expect.error(w.setVisible, nil):eq("bad argument #1 (expected boolean, got nil)") | ||||
|             expect.error(w.setVisible, nil):eq("bad argument #1 (boolean expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|     describe("Window.isVisible", function() | ||||
|   | ||||
| @@ -10,14 +10,14 @@ describe("The Lua base library", function() | ||||
|             sleep(0) | ||||
|             sleep(nil) | ||||
|  | ||||
|             expect.error(sleep, false):eq("bad argument #1 (expected number, got boolean)") | ||||
|             expect.error(sleep, false):eq("bad argument #1 (number expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("write", function() | ||||
|         it("validates arguments", function() | ||||
|             write("") | ||||
|             expect.error(write, nil):eq("bad argument #1 (expected string or number, got nil)") | ||||
|             expect.error(write, nil):eq("bad argument #1 (string or number expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("writes numbers", function() | ||||
| @@ -43,9 +43,9 @@ describe("The Lua base library", function() | ||||
|             loadfile("", "") | ||||
|             loadfile("", "", {}) | ||||
|  | ||||
|             expect.error(loadfile, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(loadfile, "", false):eq("bad argument #2 (expected string, got boolean)") | ||||
|             expect.error(loadfile, "", "", false):eq("bad argument #3 (expected table, got boolean)") | ||||
|             expect.error(loadfile, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(loadfile, "", false):eq("bad argument #2 (string expected, got boolean)") | ||||
|             expect.error(loadfile, "", "", false):eq("bad argument #3 (table expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("prefixes the filename with @", function() | ||||
| @@ -74,7 +74,7 @@ describe("The Lua base library", function() | ||||
|     describe("dofile", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(dofile, ""):eq("File not found") | ||||
|             expect.error(dofile, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(dofile, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -87,10 +87,10 @@ describe("The Lua base library", function() | ||||
|             load("", "", "") | ||||
|             load("", "", "", _ENV) | ||||
|  | ||||
|             expect.error(load, nil):eq("bad argument #1 (expected function or string, got nil)") | ||||
|             expect.error(load, "", false):eq("bad argument #2 (expected string, got boolean)") | ||||
|             expect.error(load, "", "", false):eq("bad argument #3 (expected string, got boolean)") | ||||
|             expect.error(load, "", "", "", false):eq("bad argument #4 (expected table, got boolean)") | ||||
|             expect.error(load, nil):eq("bad argument #1 (function or string expected, got nil)") | ||||
|             expect.error(load, "", false):eq("bad argument #2 (string expected, got boolean)") | ||||
|             expect.error(load, "", "", false):eq("bad argument #3 (string expected, got boolean)") | ||||
|             expect.error(load, "", "", "", false):eq("bad argument #4 (table expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         local function generator(parts) | ||||
|   | ||||
| @@ -0,0 +1,11 @@ | ||||
| -- SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers | ||||
| -- | ||||
| -- SPDX-License-Identifier: MPL-2.0 | ||||
|  | ||||
| describe("Function calls into \"native\" CC code", function() | ||||
|     it("supports custom type names", function() | ||||
|         local value = setmetatable({}, { __name = "some type" }) | ||||
|  | ||||
|         expect.error(redstone.setOutput, value):eq("bad argument #1 (string expected, got some type)") | ||||
|     end) | ||||
| end) | ||||
| @@ -10,17 +10,17 @@ describe("cc.expect", function() | ||||
|             expect(e.expect(1, "test", "string")):eq("test") | ||||
|             expect(e.expect(1, 2, "number")):eq(2) | ||||
|  | ||||
|             expect.error(e.expect, 1, nil, "string"):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(e.expect, 2, 1, "nil"):eq("bad argument #2 (expected nil, got number)") | ||||
|             expect.error(e.expect, 1, nil, "string"):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(e.expect, 2, 1, "nil"):eq("bad argument #2 (nil expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("checks multiple types", function() | ||||
|             expect(e.expect(1, "test", "string", "number")):eq("test") | ||||
|             expect(e.expect(1, 2, "string", "number")):eq(2) | ||||
|  | ||||
|             expect.error(e.expect, 1, nil, "string", "number"):eq("bad argument #1 (expected string or number, got nil)") | ||||
|             expect.error(e.expect, 1, nil, "string", "number"):eq("bad argument #1 (string or number expected, got nil)") | ||||
|             expect.error(e.expect, 2, false, "string", "table", "number", "nil") | ||||
|                 :eq("bad argument #2 (expected string, table or number, got boolean)") | ||||
|                 :eq("bad argument #2 (string, table or number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("includes the function name", function() | ||||
| @@ -31,13 +31,13 @@ describe("cc.expect", function() | ||||
|                 worker() | ||||
|             end | ||||
|  | ||||
|             expect.error(trampoline):str_match("^[^:]*expect_spec.lua:31: bad argument #1 to 'worker' %(expected string, got nil%)$") | ||||
|             expect.error(trampoline):str_match("^[^:]*expect_spec.lua:31: bad argument #1 to 'worker' %(string expected, got nil%)$") | ||||
|         end) | ||||
|  | ||||
|         it("supports custom type names", function() | ||||
|             local value = setmetatable({}, { __name = "some type" }) | ||||
|  | ||||
|             expect.error(e.expect, 1, value, "string"):eq("bad argument #1 (expected string, got some type)") | ||||
|             expect.error(e.expect, 1, value, "string"):eq("bad argument #1 (string expected, got some type)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -47,7 +47,7 @@ describe("cc.expect", function() | ||||
|             expect(e.field({ k = 2 }, "k", "number")):eq(2) | ||||
|  | ||||
|             expect.error(e.field, { k = nil }, "k", "string"):eq("field 'k' missing from table") | ||||
|             expect.error(e.field, { l = 1 }, "l", "nil"):eq("bad field 'l' (expected nil, got number)") | ||||
|             expect.error(e.field, { l = 1 }, "l", "nil"):eq("bad field 'l' (nil expected, got number)") | ||||
|         end) | ||||
|  | ||||
|         it("checks multiple types", function() | ||||
| @@ -57,7 +57,7 @@ describe("cc.expect", function() | ||||
|             expect.error(e.field, { k = nil }, "k", "string", "number") | ||||
|                 :eq("field 'k' missing from table") | ||||
|             expect.error(e.field, { l = false }, "l", "string", "table", "number", "nil") | ||||
|                 :eq("bad field 'l' (expected string, table or number, got boolean)") | ||||
|                 :eq("bad field 'l' (string, table or number expected, got boolean)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|   | ||||
| @@ -10,7 +10,7 @@ describe("cc.image.nft", function() | ||||
|     describe("parse", function() | ||||
|         it("validates arguments", function() | ||||
|             nft.parse("") | ||||
|             expect.error(nft.parse, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(nft.parse, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("parses an empty string", function() | ||||
| @@ -44,7 +44,7 @@ describe("cc.image.nft", function() | ||||
|     describe("load", function() | ||||
|         it("validates arguments", function() | ||||
|             nft.load("") | ||||
|             expect.error(nft.load, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(nft.load, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("loads from a file", function() | ||||
| @@ -65,10 +65,10 @@ describe("cc.image.nft", function() | ||||
|  | ||||
|     describe("draw", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(nft.draw, nil):eq("bad argument #1 (expected table, got nil)") | ||||
|             expect.error(nft.draw, {}, nil):eq("bad argument #2 (expected number, got nil)") | ||||
|             expect.error(nft.draw, {}, 1, nil):eq("bad argument #3 (expected number, got nil)") | ||||
|             expect.error(nft.draw, {}, 1, 1, false):eq("bad argument #4 (expected table, got boolean)") | ||||
|             expect.error(nft.draw, nil):eq("bad argument #1 (table expected, got nil)") | ||||
|             expect.error(nft.draw, {}, nil):eq("bad argument #2 (number expected, got nil)") | ||||
|             expect.error(nft.draw, {}, 1, nil):eq("bad argument #3 (number expected, got nil)") | ||||
|             expect.error(nft.draw, {}, 1, 1, false):eq("bad argument #4 (table expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("draws an image", function() | ||||
|   | ||||
| @@ -21,8 +21,8 @@ describe("cc.pretty", function() | ||||
|         end) | ||||
|  | ||||
|         it("validates arguments", function() | ||||
|             expect.error(pp.text, 123):eq("bad argument #1 (expected string, got number)") | ||||
|             expect.error(pp.text, "", ""):eq("bad argument #2 (expected number, got string)") | ||||
|             expect.error(pp.text, 123):eq("bad argument #1 (string expected, got number)") | ||||
|             expect.error(pp.text, "", ""):eq("bad argument #2 (number expected, got string)") | ||||
|         end) | ||||
|  | ||||
|         it("produces text documents", function() | ||||
| @@ -62,8 +62,8 @@ describe("cc.pretty", function() | ||||
|         end) | ||||
|  | ||||
|         it("validates arguments", function() | ||||
|             expect.error(pp.concat, 123):eq("bad argument #1 (expected document, got number)") | ||||
|             expect.error(pp.concat, "", {}):eq("bad argument #2 (expected document, got table)") | ||||
|             expect.error(pp.concat, 123):eq("bad argument #1 (document expected, got number)") | ||||
|             expect.error(pp.concat, "", {}):eq("bad argument #2 (document expected, got table)") | ||||
|         end) | ||||
|  | ||||
|         it("can be used as an operator", function() | ||||
|   | ||||
| @@ -9,8 +9,8 @@ describe("cc.pretty", function() | ||||
|         it("validates arguments", function() | ||||
|             str.wrap("test string is long") | ||||
|             str.wrap("test string is long", 11) | ||||
|             expect.error(str.wrap, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(str.wrap, "", false):eq("bad argument #2 (expected number, got boolean)") | ||||
|             expect.error(str.wrap, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(str.wrap, "", false):eq("bad argument #2 (number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("wraps lines", function() | ||||
| @@ -31,8 +31,8 @@ describe("cc.pretty", function() | ||||
|         it("validates arguments", function() | ||||
|             str.wrap("test string is long") | ||||
|             str.wrap("test string is long", 11) | ||||
|             expect.error(str.ensure_width, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(str.ensure_width, "", false):eq("bad argument #2 (expected number, got boolean)") | ||||
|             expect.error(str.ensure_width, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(str.ensure_width, "", false):eq("bad argument #2 (number expected, got boolean)") | ||||
|         end) | ||||
|  | ||||
|         it("pads lines", function() | ||||
|   | ||||
| @@ -6,29 +6,29 @@ describe("The multishell program", function() | ||||
|     describe("multishell.setFocus", function() | ||||
|         it("validates arguments", function() | ||||
|             multishell.setFocus(multishell.getFocus()) | ||||
|             expect.error(multishell.setFocus, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(multishell.setFocus, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("multishell.getTitle", function() | ||||
|         it("validates arguments", function() | ||||
|             multishell.getTitle(1) | ||||
|             expect.error(multishell.getTitle, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(multishell.getTitle, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("multishell.setTitle", function() | ||||
|         it("validates arguments", function() | ||||
|             multishell.setTitle(1, multishell.getTitle(1)) | ||||
|             expect.error(multishell.setTitle, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(multishell.setTitle, 1, nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(multishell.setTitle, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(multishell.setTitle, 1, nil):eq("bad argument #2 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("multishell.launch", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(multishell.launch, nil):eq("bad argument #1 (expected table, got nil)") | ||||
|             expect.error(multishell.launch, _ENV, nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(multishell.launch, nil):eq("bad argument #1 (table expected, got nil)") | ||||
|             expect.error(multishell.launch, _ENV, nil):eq("bad argument #2 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
|   | ||||
| @@ -8,7 +8,7 @@ describe("The shell", function() | ||||
|     describe("require", function() | ||||
|         it("validates arguments", function() | ||||
|             require("math") | ||||
|             expect.error(require, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(require, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
| @@ -98,7 +98,7 @@ describe("The shell", function() | ||||
|     describe("shell.setDir", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.setDir(shell.dir()) | ||||
|             expect.error(shell.setDir, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.setDir, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|  | ||||
|         it("not existing directory", function() | ||||
| @@ -109,63 +109,63 @@ describe("The shell", function() | ||||
|     describe("shell.setPath", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.setPath(shell.path()) | ||||
|             expect.error(shell.setPath, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.setPath, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.resolve", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.resolve("") | ||||
|             expect.error(shell.resolve, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.resolve, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.resolveProgram", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.resolveProgram("ls") | ||||
|             expect.error(shell.resolveProgram, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.resolveProgram, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.complete", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.complete("ls") | ||||
|             expect.error(shell.complete, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.complete, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.setCompletionFunction", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(shell.setCompletionFunction, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.setCompletionFunction, "", nil):eq("bad argument #2 (expected function, got nil)") | ||||
|             expect.error(shell.setCompletionFunction, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(shell.setCompletionFunction, "", nil):eq("bad argument #2 (function expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.setCompletionFunction", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(shell.setCompletionFunction, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.setCompletionFunction, "", nil):eq("bad argument #2 (expected function, got nil)") | ||||
|             expect.error(shell.setCompletionFunction, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(shell.setCompletionFunction, "", nil):eq("bad argument #2 (function expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.setAlias", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.setAlias("sl", "ls") | ||||
|             expect.error(shell.setAlias, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.setAlias, "", nil):eq("bad argument #2 (expected string, got nil)") | ||||
|             expect.error(shell.setAlias, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|             expect.error(shell.setAlias, "", nil):eq("bad argument #2 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.clearAlias", function() | ||||
|         it("validates arguments", function() | ||||
|             shell.clearAlias("sl") | ||||
|             expect.error(shell.clearAlias, nil):eq("bad argument #1 (expected string, got nil)") | ||||
|             expect.error(shell.clearAlias, nil):eq("bad argument #1 (string expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|     describe("shell.switchTab", function() | ||||
|         it("validates arguments", function() | ||||
|             expect.error(shell.switchTab, nil):eq("bad argument #1 (expected number, got nil)") | ||||
|             expect.error(shell.switchTab, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|         end) | ||||
|     end) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates