Commits

Taku Miyakawa committed b93be6c

Improves \env.show

  • Participants
  • Parent commits f66854c

Comments (0)

Files changed (5)

src/main/java/org/kink_lang/kink/Modules.java

 
 
     /** Finds a kink module; returns {@code null} if absent. */
-    static Value findKink( String moduleName ) {
+    static Value findKink( final String moduleName ) {
         Program program = findProgram( moduleName );
         if ( program == null ) {
             return null;
         }
         LOGGER.debug( "Load module {} from {}" , moduleName , program.getName() );
         Value env = Envs.env();
+        Fun showFun = new Fun() {
+            @Override public Value run( Value actualEnv , Value ... args ) {
+                String show = "<env:#module_name=" + Strings.show( moduleName )
+                    + ":hash=" + actualEnv.hashCode() + ">";
+                return Value.value( show );
+            }
+        };
+        env.set( SET_SHOW , Value.value( showFun ) );
         program.compile().call( env );
 
         Set< String > publicSymbols = Envs.publicMethodSymbols( env );

src/main/java/org/kink_lang/kink/internal/module/Core.java

 
         @Define
         public Value show( @Receiver Value envOrCore ) {
-            return Value.value( envOrCore == CoreHolder.CORE ? "CORE" : "<env>" );
+            return Value.value( envOrCore == CoreHolder.CORE
+                    ? "CORE"
+                    : "<env:hash=" + envOrCore.hashCode() + ">" );
         }
 
 

src/main/kink/REPL.kn

 :Env_proto = module('CORE').child(
     'show' { > :Env ()
         use('SHOW')
-        SHOW.builder('env').add('<belonging>' 'repl'.show).build(Env)
+        SHOW.builder('env')
+        .add('#repl' '(repl)'.show)
+        .add('hash')
+        .build(Env)
     }
 )
 

src/test/java/org/kink_lang/kink/internal/module/CoreTest.java

 
     @Test
     public void show_of_child_of_core() {
-        assertThat( core.child().call( new GetSite( "show" ) ).asString( "" ) , is( "<env>" ) );
+        String show = core.child().call( new GetSite( "show" ) ).asString( "" );
+        assertThat( show.matches( "<env:hash=[0-9]+>" ) , is( true ) );
     }
 
 

src/test/kink/spec/MODULE_ENV_SHOW.kn

+#!/usr/bin/env kink
+# vim: et sw=4 sts=4
+
+use('TEST.test')
+
+test {
+    \env.show.check(%"<env:#module_name='spec/MODULE_ENV_SHOW':hash=[0-9]+>")
+}