annotate Libs/LibStub/tests/test.lua @ 11:2f09fe4be15c

Added an Options Panel.
author Tercio
date Mon, 20 Apr 2015 16:34:18 -0300
parents 1c3534391efb
children
rev   line source
Tercio@4 1 debugstack = debug.traceback
Tercio@4 2 strmatch = string.match
Tercio@4 3
Tercio@4 4 loadfile("../LibStub.lua")()
Tercio@4 5
Tercio@4 6 local lib, oldMinor = LibStub:NewLibrary("Pants", 1) -- make a new thingy
Tercio@4 7 assert(lib) -- should return the library table
Tercio@4 8 assert(not oldMinor) -- should not return the old minor, since it didn't exist
Tercio@4 9
Tercio@4 10 -- the following is to create data and then be able to check if the same data exists after the fact
Tercio@4 11 function lib:MyMethod()
Tercio@4 12 end
Tercio@4 13 local MyMethod = lib.MyMethod
Tercio@4 14 lib.MyTable = {}
Tercio@4 15 local MyTable = lib.MyTable
Tercio@4 16
Tercio@4 17 local newLib, newOldMinor = LibStub:NewLibrary("Pants", 1) -- try to register a library with the same version, should silently fail
Tercio@4 18 assert(not newLib) -- should not return since out of date
Tercio@4 19
Tercio@4 20 local newLib, newOldMinor = LibStub:NewLibrary("Pants", 0) -- try to register a library with a previous, should silently fail
Tercio@4 21 assert(not newLib) -- should not return since out of date
Tercio@4 22
Tercio@4 23 local newLib, newOldMinor = LibStub:NewLibrary("Pants", 2) -- register a new version
Tercio@4 24 assert(newLib) -- library table
Tercio@4 25 assert(rawequal(newLib, lib)) -- should be the same reference as the previous
Tercio@4 26 assert(newOldMinor == 1) -- should return the minor version of the previous version
Tercio@4 27
Tercio@4 28 assert(rawequal(lib.MyMethod, MyMethod)) -- verify that values were saved
Tercio@4 29 assert(rawequal(lib.MyTable, MyTable)) -- verify that values were saved
Tercio@4 30
Tercio@4 31 local newLib, newOldMinor = LibStub:NewLibrary("Pants", "Blah 3 Blah") -- register a new version with a string minor version (instead of a number)
Tercio@4 32 assert(newLib) -- library table
Tercio@4 33 assert(newOldMinor == 2) -- previous version was 2
Tercio@4 34
Tercio@4 35 local newLib, newOldMinor = LibStub:NewLibrary("Pants", "Blah 4 and please ignore 15 Blah") -- register a new version with a string minor version (instead of a number)
Tercio@4 36 assert(newLib)
Tercio@4 37 assert(newOldMinor == 3) -- previous version was 3 (even though it gave a string)
Tercio@4 38
Tercio@4 39 local newLib, newOldMinor = LibStub:NewLibrary("Pants", 5) -- register a new library, using a normal number instead of a string
Tercio@4 40 assert(newLib)
Tercio@4 41 assert(newOldMinor == 4) -- previous version was 4 (even though it gave a string)