annotate Libs/LibStub/tests/test2.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 for major, library in LibStub:IterateLibraries() do
Tercio@4 7 -- check that MyLib doesn't exist yet, by iterating through all the libraries
Tercio@4 8 assert(major ~= "MyLib")
Tercio@4 9 end
Tercio@4 10
Tercio@4 11 assert(not LibStub:GetLibrary("MyLib", true)) -- check that MyLib doesn't exist yet by direct checking
Tercio@4 12 assert(not pcall(LibStub.GetLibrary, LibStub, "MyLib")) -- don't silently fail, thus it should raise an error.
Tercio@4 13 local lib = LibStub:NewLibrary("MyLib", 1) -- create the lib
Tercio@4 14 assert(lib) -- check it exists
Tercio@4 15 assert(rawequal(LibStub:GetLibrary("MyLib"), lib)) -- verify that :GetLibrary("MyLib") properly equals the lib reference
Tercio@4 16
Tercio@4 17 assert(LibStub:NewLibrary("MyLib", 2)) -- create a new version
Tercio@4 18
Tercio@4 19 local count=0
Tercio@4 20 for major, library in LibStub:IterateLibraries() do
Tercio@4 21 -- check that MyLib exists somewhere in the libraries, by iterating through all the libraries
Tercio@4 22 if major == "MyLib" then -- we found it!
Tercio@4 23 count = count +1
Tercio@4 24 assert(rawequal(library, lib)) -- verify that the references are equal
Tercio@4 25 end
Tercio@4 26 end
Tercio@4 27 assert(count == 1) -- verify that we actually found it, and only once