2012-04-22 18:12:33 +00:00
|
|
|
--
|
|
|
|
-- tests/api/test_list_kind.lua
|
|
|
|
-- Tests the list API value type.
|
|
|
|
-- Copyright (c) 2012 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
T.api_list_kind = {}
|
|
|
|
local suite = T.api_list_kind
|
|
|
|
local api = premake.api
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Setup and teardown
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.setup()
|
|
|
|
api.register {
|
|
|
|
name = "testapi",
|
2014-01-14 21:43:14 +00:00
|
|
|
kind = "string",
|
|
|
|
list = true,
|
2012-04-22 18:12:33 +00:00
|
|
|
scope = "project",
|
|
|
|
allowed = { "first", "second", "third" }
|
|
|
|
}
|
|
|
|
test.createsolution()
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.teardown()
|
|
|
|
testapi = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Table values should be stored as-is.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.storesTable_onArrayValue()
|
|
|
|
testapi { "first", "second" }
|
|
|
|
test.isequal({ "first", "second" }, api.scope.project.testapi)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- String values should be converted into a table.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.storesTable_onStringValue()
|
|
|
|
testapi "first"
|
|
|
|
test.isequal({ "first" }, api.scope.project.testapi)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-01-14 21:43:14 +00:00
|
|
|
--
|
2012-04-22 18:12:33 +00:00
|
|
|
-- New values should be appended to any previous values.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.overwrites_onNewValue()
|
|
|
|
testapi "first"
|
|
|
|
testapi "second"
|
|
|
|
test.isequal({ "first", "second" }, api.scope.project.testapi)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Nested lists should be flattened.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.flattensValues_onNestedLists()
|
|
|
|
testapi { { "first" }, { "second" } }
|
|
|
|
test.isequal({ "first", "second" }, api.scope.project.testapi)
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- If an allowed values list is present, make sure it gets applied.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.raisesError_onDisallowedValue()
|
2014-01-14 21:43:14 +00:00
|
|
|
ok, err = pcall(function ()
|
2012-04-22 18:12:33 +00:00
|
|
|
testapi "NotAllowed"
|
|
|
|
end)
|
|
|
|
test.isfalse(ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.convertsCase_onAllowedValue()
|
|
|
|
testapi "seCOnd"
|
|
|
|
test.isequal({ "second" }, api.scope.project.testapi)
|
|
|
|
end
|