1. Kink Programming Language
  2. Untitled project
  3. kink

Commits

Taku Miyakawa  committed 43cbbb5

Refactors TEST module

  • Participants
  • Parent commits 9c3eab2
  • Branches default

Comments (0)

Files changed (1)

File src/main/kink/TEST.kn

View file
 use('THREAD_LOCAL_STORAGE')
 use('java.util.concurrent.atomic.AtomicLong')
 
+# Provider of node ids.
 :Node_id_provider = AtomicLong.new
 
-
-:Preparing_group_tls = THREAD_LOCAL_STORAGE.new
-
+# Returns a new node id.
 :_new_id = {
     Node_id_provider.getAndIncrement
 }
 
-:_preparing_test_group = {
+# TLS of current groups.
+:Preparing_group_tls = THREAD_LOCAL_STORAGE.new
+
+# Returns a group currently being prepared.
+:_current_group = {
     Preparing_group_tls.get { Dummy_group }
 }
 
+# Prepares a group in the block.
 :_preparing = { (:Test_group :Block)
     Preparing_group_tls.setting(Test_group Block)
 }
 
+# Dummy virtual group on the top.
 :Dummy_group = value(
-    '_test_group' { (* :Args)
-        _test_group(*** Args)
+    '_child_test_group' { (:Args)
+        _new_test_group(Args Dummy_group)
     }
-    '_test' { (* :Args)
-        _test(*** Args)
+    '_child_test' { (:Args)
+        _new_test(Args Dummy_group)
     }
     'full_ids' { [] }
     'full_descriptions' { [] }
 
 # Trait for test nodes.
 :Test_node_trait = [
-    # Id of the test node.
-    'Id' ()
+
+    # Initializes the test node.
+    '_init_test_node' { > :Test_ndoe (:Id :Description :Parent_virtual_group)
+        Test_ndoe.set_vars(
+            # Id of the test node.
+            'Id' Id
+
+            # Description of the test node.
+            'Description' Description
+
+            # Parent virtual group.
+            'Parent_virtual_group' Parent_virtual_group
+        )
+    }
 
     # Id of the test node.
     'id' { > :Test_node ()
         Test_node.Parent_virtual_group.full_ids + [Test_node.id]
     }
 
-    'Description' ()
-
     'description' { > :Test_node ()
         Test_node.Description
     }
         Test_node.Parent_virtual_group.full_descriptions + [Test_node.description]
     }
 
-    'Parent_virtual_group' Dummy_group
-
     'has_parent_group?' { > :Self ()
         Self.Parent_virtual_group != Dummy_group
     }
     }
 ]
 
-:test_group = {
-    _preparing_test_group._test_group(*** \args)
+:test_group = { (* :Args)
+    _current_group._child_test_group(Args)
 }
 
 # Prototype of test groups.
 :Test_group_proto = value(
     *** Test_node_trait
+
+    '_init_test_group' { > :Self_group (:Id :Description :Parent_virtual_group)
+        Self_group._init_test_node(Id Description Parent_virtual_group)
+        .set_vars(
+            'Child_nodes' []
+            'Before_blocks' []
+            'After_blocks' []
+            'Set_up_refs' []
+        )
+    }
+
     'test_group??' { true }
-    '_test_group' { > :Self_group
-        :Child_test_group = _test_group(*** \args).set_vars(
-            'Parent_virtual_group' Self_group
-        )
+    '_child_test_group' { > :Self_group (:Args)
+        :Child_test_group = _new_test_group(Args Self_group)
         Self_group.child_nodes.push(Child_test_group)
         Child_test_group
     }
-    '_test' { > :Self_group
-        :Child_test = _test(*** \args).set_vars(
-            'Parent_virtual_group' Self_group
-        )
+    '_child_test' { > :Self_group (:Args)
+        :Child_test = _new_test(Args Self_group)
         Self_group.child_nodes.push(Child_test)
         Child_test
     }
-    'Before_blocks' []
     '_before' { > :Self_group (:Block)
         Self_group.Before_blocks.push(Block.with_no_trace)
         Self_group
             _before_block
         }
     }
-    'After_blocks' []
     '_after' { > :Self_group (:Block)
         Self_group.After_blocks.push(Block.with_no_trace)
         Self_group
             }
         }
     }
-    'Set_up_refs' []
     '_set_up' { > :Self_group (:Ref :Block)
         :_make_value = Block.with_no_trace
         Self_group._before {
             Child_node.pending(Pending_reason)
         }
     }
-    'Child_nodes' []
     'child_nodes' { > :Self_group ()
         Self_group.Child_nodes
     }
         SHOW_BUILDER.new('test_group').add('full_ids').add('full_descriptions').build(Self)
     }
 )
+._init_test_group(_new_id 'Test group' Dummy_group)
 
-:_test_group = { (* :Args)
+:_new_test_group = { (:Args :Parent_virtual_group)
     :Id = _new_id
     [:Description :_setting_up] = Args.switch(
         [] {
         }
         (any) { throw('Not yet implemented') }
     )
-    Test_group_proto.child(
-        'Id' Id
-        'Description' Description
-        'Child_nodes' []
-        'Before_blocks' []
-        'After_blocks' []
-        'Set_up_refs' []
-    )
+    Test_group_proto.child._init_test_group(Id Description Parent_virtual_group)
     .in { _setting_up }
 }
 
 
 :Test_proto = value(
     *** Test_node_trait
+    '_init_test' { > :Self_test (:Id :Description :Parent_virtual_group)
+        Self_test._init_test_node(Id Description Parent_virtual_group)
+    }
     '_test_fun' {}
     'Block_specified?' false
     'in' { > :Self_test (:_test_fun)
         Self_test.:_test_fun = $_test_fun.with_no_trace
         Self_test
     }
-    'Set_pending?' false
+    'Set_as_pending?' false
     'Pending_reason' 'No test block specified'
     'pending' { > :Self_test (:Pending_reason)
-        Self_test.:Set_pending? = true
+        Self_test.:Set_as_pending? = true
         Self_test.:Pending_reason = Pending_reason
         Self_test
     }
     'pending?' { > :Self_test ()
-        Self_test.Set_pending? || ! Self_test.Block_specified?
+        Self_test.Set_as_pending? || ! Self_test.Block_specified?
     }
     'run' { > :Self_test (:Listener = Nop_listener)
         Listener.on_start(Self_test)
 
     'test??' { true }
 )
+._init_test(_new_id 'Test' Dummy_group)
 
-:test = {
-    _preparing_test_group._test(*** \args)
+:test = { (* :Args)
+    _current_group._child_test(Args)
 }
 
-:_test = { (* :Args)
+:_new_test = { (:Args :Parent_virtual_group)
     :Id = _new_id
     [:Description :Maybe_test_block] = Args.switch(
         [] {
         [:Description :Test_block] {
             [Description [Test_block]]
         }
-        (any) { throw('Not yet implemented') }
+        (any) {
+            throw('Not yet implemented')
+        }
     )
-    :Test = Test_proto.child(
-        'Id' Id
-        'Description' Description
-    )
+    :Test = Test_proto.child._init_test(Id Description Parent_virtual_group)
     Maybe_test_block.switch(
         [:Test_block] { Test.in(Test_block) }
     )
 }
 
 :before = { (:Block)
-    _preparing_test_group._before(Block)
+    _current_group._before(Block)
 }
 
 :after = { (:Block)
-    _preparing_test_group._after(Block)
+    _current_group._after(Block)
 }
 
 :set_up = { (:Ref :Block)
-    _preparing_test_group._set_up(Ref Block)
+    _current_group._set_up(Ref Block)
 }