annotate Libs/LibStub/tests/test2.lua @ 0:0de01324b4f2

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