<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>loonar/hash.lua</filename>
    </added>
    <added>
      <filename>spec/class.lua</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -11,13 +11,12 @@ function class(class_object)
     __lt = '&lt;', __le = '&lt;=',  __eq = '==';
     -- Arithmetic
     __add = '+', __sub = '-', __mul = '*', __div = '/', __pow = '^';
-    
+    -- Unary negation
+    __unm = '-neg';
     __concat = '..';
     __call = '__call';
     __tostring = 'tostring';
     __gc = 'destroy';
---  this is negation not subtraction, what is the best api for this? 'neg'?
---  __unm = '-'; 
   }
 
   local class_object = class_object or {}
@@ -36,6 +35,8 @@ function class(class_object)
       return function(...)
         return class_object[member](self, ...)
       end
+    elseif type(member) == 'string' and type(class_object['.'..member]) == 'function' then
+      return class_object['.'..member](self)
     elseif type(instance_protocol.___index) == 'function' then
       return instance_protocol.___index(self, member)
     else
@@ -61,6 +62,8 @@ function class(class_object)
     class_object.initialize = constructor
   elseif type(class_object.initialize) == 'function' then
     constructor = class_object.initialize
+  else 
+    class_object.initialize = constructor
   end
 
   local class_protocol = {</diff>
      <filename>loonar/class.lua</filename>
    </modified>
    <modified>
      <diff>@@ -1,31 +1,40 @@
--- Lua spec
---		Provide excutable specification
---
--- Limitation:
---		lua seem to order the key when using table as hash to store specs
---		So its out of order, but shouldn't affect us	
-
--- Example:
-----------------------
--- describe (&quot;string&quot;)
--- {
--- 
---   before = function(self)
---     self.value = &quot;hello world&quot;
---   end;
---  
---   [&quot;transforms to upper case&quot;] = function(self)
---     expect(self.value:upper()).should_be 'HELLO WORLD'
---   end;
--- 
---   [&quot;matches pattern /hello/&quot;] = function(self)
---    
---     expect(self.value).should_match 'hello'
---   end;
--- 
---   after = function() end
--- }
-
+--[[
+Lua spec
+    Provide excutable specification
+
+Explaination:
+  - a spec can have one or more context 
+  - a context have one or more examples
+  - a example have one or more expectations
+
+Example:
+  -- Describe a context
+  describe (&quot;string&quot;)
+  {
+    -- setup [optional]
+    before = function(self)
+      self.value = &quot;hello world&quot;
+    end;
+   
+    -- This is a example
+    [&quot;transforms to upper case&quot;] = function(self)
+      expect(self.value:upper()).should_be 'HELLO WORLD' -- Expectation
+    end;
+    
+    -- Another example
+    [&quot;matches pattern&quot;] = function(self)
+      expect(self.value).should_match 'world'
+      expect(self.value).should_match 'hello'
+    end;
+    
+    -- cleanup [optional]
+    after = function() end
+  }
+  
+Limitation:
+  - lua store hash alphabetically with key, so our context executed
+    alphabetically, example in a context executed alphabetically
+--]]
 
 spec = {
   contexts = {}, passed = 0, failed = 0, verbose = false, current = nil
@@ -33,37 +42,44 @@ spec = {
 
 -- Report spec failure and success rates
 spec.report = function ()
-	local total = spec.passed + spec.failed
-	local percent = spec.passed/total*100
-	
-	if spec.failed == 0 and not spec.verbose then
-		print &quot;all tests passed&quot;
-		return
-	end
-	
-	for context, cases in pairs(spec.contexts) do
-		print (context)
-		print &quot;================================&quot;
-		
-		for description, result in pairs(cases) do
-			local outcome = result.passed and 'passed' or &quot;failed&quot;
-			
-			if spec.verbose or (not spec.verbose and not result.passed) then
-				print (&quot; - &quot;..description..&quot; :\t\t[ &quot;..outcome..&quot; ]&quot;)
-				print &quot;   ----------------------------&quot;
-
-				if not result.passed and result.trace then
-					print (&quot;   message :\n\t&quot;.. result.message..&quot;\n   &quot;..result.trace)
-				end
-			end
-		end
-	end
-	
-	print (total..&quot; Expectations &quot;)
-	print (string.format(&quot;  Passed : %s Failed : %s Success rate : %.2f percent&quot;, spec.passed, spec.failed, percent))
-	print '================================'
+  local total = spec.passed + spec.failed
+  local percent = spec.passed/total*100
+  local summery
+  if spec.failed == 0 and not spec.verbose then
+    print &quot;all tests passed&quot;
+    return
+  end
+  
+  for context, cases in pairs(spec.contexts) do
+    print ((&quot;%s\n================================&quot;):format(context))
+    for description, result in pairs(cases) do
+      local outcome = result.passed and 'pass' or &quot;FAILED&quot;
+
+      if spec.verbose or not (spec.verbose and result.passed) then
+        print((&quot;%-70s [ %s ]&quot;):format(&quot; - &quot; .. description, outcome))
+
+        table.foreach(result.errors, function(index, error)
+          print (&quot;   &quot;.. index..&quot;. Failed expectation : &quot;.. error.message..&quot;\n   &quot;..error.trace)
+        end)
+      end
+    end
+  end
+  
+  summery = [[
+=========  Summery  ============
+  %s Expectations
+    Passed : %s, Failed : %s, Success rate : %.2f percent
+  ]]
+  
+  print (summery:format(total, spec.passed, spec.failed, percent))
 end
 
+spec.add_example = function()
+end;
+
+spec.add_expectation = function()
+end;
+
 --
 -- Collection of should matchers
  
@@ -76,43 +92,43 @@ matchers = {
   end;
   
   should_be_true = function(self)
-		if self.value ~= true then
-			return false, &quot;expecting true, not &quot; .. self.value
-		end
-		return true
+    if self.value ~= true then
+      return false, &quot;expecting true, not &quot; .. self.value
+    end
+    return true
   end;
   
   should_be_false = function(self) 
-		if self.value ~= false then
-			return false, &quot;expecting false, not &quot; .. self.value
-		end
-		return true
-	end;
-	
+    if self.value ~= false then
+      return false, &quot;expecting false, not &quot; .. self.value
+    end
+    return true
+  end;
+  
   should_be_nil = function(self) 
-		if self.value ~= nil then
-			return false, &quot;expecting nil, not &quot; ..self.value
-		end
-		return true
-	end;
-	
+    if self.value ~= nil then
+      return false, &quot;expecting nil, not &quot; ..self.value
+    end
+    return true
+  end;
+  
   should_not_be = function(self, expected)
-		if self.value == expected then
-			return false, &quot;should not be &quot;..self.value
-		end
-		return true
-	end;
+    if self.value == expected then
+      return false, &quot;should not be &quot;..self.value
+    end
+    return true
+  end;
 
   should_match = function(self, pattern) 
-		if type(self.value) ~= 'string' then
-			return false, &quot;type error, should_match expecting target as string&quot;
-		end
-		
-		if not string.match(self.value, pattern) then
-			return false, self.value .. &quot;doesn't match pattern &quot;..pattern
-		end
-		return true
-	end;	
+    if type(self.value) ~= 'string' then
+      return false, &quot;type error, should_match expecting target as string&quot;
+    end
+    
+    if not string.match(self.value, pattern) then
+      return false, self.value .. &quot;doesn't match pattern &quot;..pattern
+    end
+    return true
+  end;	
 }
  
 matchers.should_equal = matchers.should_be
@@ -120,34 +136,31 @@ matchers.should_equal = matchers.should_be
 -- Expectation function
 --
 function expect(target)
-  local instance = { value = target }  
-
-  local expectation = function (self, method)
-		return function(...)
+  local instance = { value = target }
+  local executor = function (self, method)
+    return function(...)
       if not matchers[method] then
-				return nil
-			end
-
-			local success, message = matchers[method](self, ...)
-
-			if success then
-				spec.current.passed = true
-				spec.passed = spec.passed + 1
-			else
-				spec.current.passed = false
-				spec.current.message = message
-				spec.current.trace = debug.traceback()
-				spec.failed = spec.failed + 1
-			end
+        return nil
+      end
+
+      local success, message = matchers[method](self, ...)
+      spec.current.passed = success
+
+      if success then
+        spec.passed = spec.passed + 1
+      else
+        table.insert(spec.current.errors , { message = message, trace = debug.traceback()} )
+        spec.failed = spec.failed + 1
+      end
     end
   end
 
-  setmetatable(instance, { __index = expectation })
+  setmetatable(instance, { __index = executor })
   return instance
 end
  
 function type_of(target)
-	return expect(type(target))
+  return expect(type(target))
 end
 
 value_of = expect
@@ -172,12 +185,12 @@ function describe(context)
     end
 
     -- run
-    for description, testcase in pairs(specs) do
+    for description, example in pairs(specs) do
       spec.contexts[context][description] = { 
-				passed = false, message = nil, trace = nil
-			}
+        passed = false, errors = {}
+      }
       spec.current = spec.contexts[context][description]
-      testcase(instance)
+      example(instance)
     end
  
     -- post routine
@@ -186,6 +199,5 @@ function describe(context)
     end
   end
 end
- 
- 
+
 </diff>
      <filename>loonar/spec.lua</filename>
    </modified>
    <modified>
      <diff>@@ -14,11 +14,11 @@ require 'loonar.array'
 
 -- Tests
 require 'spec.array'
-require 'tests.class'
+require 'spec.class'
 require 'tests.object'
-require 'tests.array'
 
 -- Report executed spec result
+spec.verbose = true
 spec.report()
 
 -- Helper functions for __LINE__ and __FILE__</diff>
      <filename>run_tests.lua</filename>
    </modified>
    <modified>
      <diff>@@ -1,102 +1,111 @@
 describe ('array') 
 {
-	before = function(self)
-		self.list = a{888}
-	end;
-	
-	[&quot;allows insertion of elements&quot;] = function(self)
-		self.list[2] = 22
-		expect(self.list[2]).should_be(22)
-	end;
-	
-	[&quot;allows array access&quot;] = function(self) 
-		expect(self.list[1]).should_be(888)
+  before = function(self)
+    self.list = a{888}
+  end;
+  
+  [&quot;array.first should return the first element&quot;] = function(self)
+    expect(self.list.first).should_be(self.list[1])
+  end;
+  
+  [&quot;array.last should return the last element&quot;] = function(self)
+    expect(self.list.last).should_be(self.list[#self.list])
+  end;
+  
+  [&quot;allows insertion of elements&quot;] = function(self)
+    self.list[2] = 22
+    expect(self.list[2]).should_be(22)
+  end;
+  
+  [&quot;allows array access&quot;] = function(self) 
+    expect(self.list[1]).should_be(888)
 
-		-- Failed expectation
-		expect(self.list[2]).should_be(2)
-	end;
+    -- Failed expectation
+    expect(self.list[2]).should_be(2)
+    expect(true).should_be(false)
+  end;
 }
 
 describe ('array - iterator') 
 {
-	before = function(self)
-		self.list = a{1,2,3,4,5} 
-	end;
-	
-	[&quot;array#each should iterate through all elements&quot;] = function(self)
-		local sum = 0
-		local list = a{1,2,3,4,5}
-		list.each(function(value) sum = sum + value end)
-		expect(sum).should_be(1+2+3+4+5)
-	end;
+  before = function(self)
+    self.list = a{1,2,3,4,5} 
+  end;
+  
+  [&quot;array#each should iterate through all elements&quot;] = function(self)
+    local sum = 0
+    local list = a{1,2,3,4,5}
+    list.each(function(value) sum = sum + value end)
+    expect(sum).should_be(1+2+3+4+5)
+  end;
 }
 
 describe ('array - transformation iterator') 
 {
-	before = function(self)
-		self.list = a{111,222,333,444}
-	end;
-	
-	[&quot;array#map should return transformed array&quot;] = function(self)
-	
-		local result = self.list.map(function(value, key) 
-	    return value + 1
-	  end)
-		
-		type_of(result).should_be 'table'
-		expect(result).should_be(a{112,223,334,445})
-		
-	end;
-	
-	[&quot;array#reduce reduces reduces to singular value&quot;] = function(self)
-		local result = self.list.reduce(0, function(sum, value) 
-	    return sum + value
-	  end)
-	
-		type_of(result).should_be &quot;number&quot;
-	  expect(result).should_be(111 + 222 + 333 + 444)
-	end;
+  before = function(self)
+    self.list = a{111,222,333,444}
+  end;
+  
+  [&quot;array#map should return transformed array&quot;] = function(self)
+  
+    local result = self.list.map(function(value, key) 
+      return value + 1
+    end)
+    
+    type_of(result).should_be 'table'
+    expect(result).should_be(a{112,223,334,445})
+    
+  end;
+  
+  [&quot;array#reduce reduces reduces to singular value&quot;] = function(self)
+    local result = self.list.reduce(0, function(sum, value) 
+      return sum + value
+    end)
+  
+    type_of(result).should_be &quot;number&quot;
+    expect(result).should_be(111 + 222 + 333 + 444)
+  end;
 }
 
 describe (&quot;array - conditional iterator&quot;) 
 {
-	before = function(self)
-		self.list = a{111,222,333,444}
-	end;
-	
-	[&quot;array#any requires condition met with any item&quot;] = function(self)
-	
-		local result = self.list.any(function(e) return e &gt; 400 end)
-		expect(result).should_be_true()
+  before = function(self)
+    self.list = a{111,222,333,444}
+  end;
+  
+  [&quot;array#any requires condition met with any item&quot;] = function(self)
+  
+    local result = self.list.any(function(e) return e &gt; 400 end)
+    expect(result).should_be_true()
 
-		result = self.list.any(function(e) return e &gt; 500 end)
-		expect(result).should_be_false()
-		
-	end;
-	
-	[&quot;array#all requires condition met with all items&quot;] = function(self)
-	
-		local result = self.list.all(function(e) return e &gt; 1 end)
-		expect(result).should_be_true()
-		
-		result = self.list.all(function(e) return e &gt; 200 end)
-		expect(result).should_be_false()
-		
-	end;
-	
-	[&quot;array#contains require if element exists&quot;] = function(self)
-	
-		expect(self.list.contains(333)).should_be_true()	
-		expect(self.list.contains(3)).should_be_false()
-		
-	end;
-	
-	[&quot;array#filter should return all element met given condition&quot;] = function(self)
-	
-	  local result = self.list.filter(function(e) return e &gt; 300 end)  
-	
-		expect(result).should_be(a{333,444})
-		expect(result == a{}).should_be_false()
-		
-	end;
+    result = self.list.any(function(e) return e &gt; 500 end)
+    expect(result).should_be_false()
+    
+  end;
+  
+  [&quot;array#all requires condition met with all items&quot;] = function(self)
+  
+    local result = self.list.all(function(e) return e &gt; 1 end)
+    expect(result).should_be_true()
+    
+    result = self.list.all(function(e) return e &gt; 200 end)
+    expect(result).should_be_false()
+    
+  end;
+  
+  [&quot;array#contains require if element exists&quot;] = function(self)
+  
+    expect(self.list.contains(333)).should_be_true()	
+    expect(self.list.contains(3)).should_be_false()
+    
+  end;
+  
+  [&quot;array#filter should return all element met given condition&quot;] = function(self)
+  
+    local result = self.list.filter(function(e) return e &gt; 300 end)  
+  
+    expect(result).should_be(a{333,444})
+    expect(result == a{}).should_be_false()
+    
+  end;
 }
\ No newline at end of file</diff>
      <filename>spec/array.lua</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,4 @@
 -- Class Example
-
 foo = class {
   self = function(self)
     return self
@@ -18,6 +17,7 @@ foo = class {
   end;
 }
 
+
   -- using default constructor
   f = foo { name = 'foo'; bar = true; tostring = 'string'; }
 
@@ -90,6 +90,8 @@ complex = class {
   end;
 }
 
+
+
   c1 = complex(1, 2)
   c2 = complex(2, 5)
 </diff>
      <filename>tests/class.lua</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bac462fe9beaad87f847a920220356093aaf7c5e</id>
    </parent>
    <parent>
      <id>e5313297ef4980ae63074bb45b72a12802d0056a</id>
    </parent>
  </parents>
  <author>
    <name>Heungsub</name>
    <email>Heungsub@Heungsub-MacBook.local</email>
  </author>
  <url>http://github.com/dahlia/loonar/commit/cc5dc07e0489ead8752bcdd3484250e80aef38a4</url>
  <id>cc5dc07e0489ead8752bcdd3484250e80aef38a4</id>
  <committed-date>2008-08-13T17:29:38-07:00</committed-date>
  <authored-date>2008-08-13T17:29:38-07:00</authored-date>
  <message>Merge branch 'master' of git@github.com:dahlia/loonar

Conflicts:

	loonar/array.lua
	run_tests.lua
	spec/array.lua</message>
  <tree>46b21b71cb3b847236f4310feeada504edfbcd16</tree>
  <committer>
    <name>Heungsub</name>
    <email>Heungsub@Heungsub-MacBook.local</email>
  </committer>
</commit>
