Commits

Taku Miyakawa  committed 41c73c1

Adds Var.empty? (closing issue #483)

  • Participants
  • Parent commits c87e21f

Comments (0)

Files changed (2)

File src/main/java/org/kink_lang/kink/internal/box/VarEnhancer.java

         }
 
 
+        @Define( "empty?" )
+        public Value empty_p( @Receiver Var var ) {
+            return Value.value( ! var.exists() );
+        }
+
+
         @Define
         public Value op_set( @Receiver Value varVal , Value content ) {
             Var var = (Var) varVal.unbox();

File src/test/java/org/kink_lang/kink/internal/box/VarEnhancerTest.java

 
 
     // }}}!
-    // Test VAR.any? {{{1
+    // Test Var.any? and Varg.empty? {{{1
 
 
     /** GetSite of {@code any?}. */
     private static final GetSite ANY_P = new GetSite( "any?" );
 
 
+    /** GetSite of {@code empty?}. */
+    private static final GetSite EMPTY_P = new GetSite( "empty?" );
+
+
     @Test
-    public void test_any_p_returns_true_when_var_exists() {
+    public void test_any_p_returns_true_and_empty_p_returns_false_when_var_exists() {
         owner.set( new SetSite( "..symbol.." ) , content );
-        Value result = Value.value( new Var( owner , "..symbol.." ) ).call( ANY_P );
-        assertThat( result.asBool( "result" ) , is( true ) );
+        Value any = Value.value( new Var( owner , "..symbol.." ) ).call( ANY_P );
+        assertThat( any.asBool( "" ) , is( true ) );
+        Value empty = Value.value( new Var( owner , "..symbol.." ) ).call( EMPTY_P );
+        assertThat( empty.asBool( "" ) , is( false ) );
     }
 
 
     @Test
     public void test_any_p_returns_false_when_var_does_not_exist() {
-        Value result = Value.value( new Var( owner , "..none.." ) ).call( ANY_P );
-        assertThat( result.asBool( "result" ) , is( false ) );
+        Value any = Value.value( new Var( owner , "..none.." ) ).call( ANY_P );
+        assertThat( any.asBool( "" ) , is( false ) );
+        Value empty = Value.value( new Var( owner , "..none.." ) ).call( EMPTY_P );
+        assertThat( empty.asBool( "" ) , is( true ) );
     }