annotate libs/LibStub/tests/test2.lua @ 1:ec3e67868c5c

Added tag 1.2.12.0 for changeset ec731d2fe6ba
author Adam tegen <adam.tegen@gmail.com>
date Tue, 20 May 2014 21:45:48 -0500
parents ec731d2fe6ba
children
rev   line source
adam@0 1 debugstack = debug.traceback
adam@0 2 strmatch = string.match
adam@0 3
adam@0 4 loadfile("../LibStub.lua")()
adam@0 5
adam@0 6 for major, library in LibStub:IterateLibraries() do
adam@0 7 -- check that MyLib doesn't exist yet, by iterating through all the libraries
adam@0 8 assert(major ~= "MyLib")
adam@0 9 end
adam@0 10
adam@0 11 assert(not LibStub:GetLibrary("MyLib", true)) -- check that MyLib doesn't exist yet by direct checking
adam@0 12 assert(not pcall(LibStub.GetLibrary, LibStub, "MyLib")) -- don't silently fail, thus it should raise an error.
adam@0 13 local lib = LibStub:NewLibrary("MyLib", 1) -- create the lib
adam@0 14 assert(lib) -- check it exists
adam@0 15 assert(rawequal(LibStub:GetLibrary("MyLib"), lib)) -- verify that :GetLibrary("MyLib") properly equals the lib reference
adam@0 16
adam@0 17 assert(LibStub:NewLibrary("MyLib", 2)) -- create a new version
adam@0 18
adam@0 19 local count=0
adam@0 20 for major, library in LibStub:IterateLibraries() do
adam@0 21 -- check that MyLib exists somewhere in the libraries, by iterating through all the libraries
adam@0 22 if major == "MyLib" then -- we found it!
adam@0 23 count = count +1
adam@0 24 assert(rawequal(library, lib)) -- verify that the references are equal
adam@0 25 end
adam@0 26 end
adam@0 27 assert(count == 1) -- verify that we actually found it, and only once