Commits

Anonymous committed d3f93a1

Some lexer tests, still enigma

I made some lexer tests. I've about reached my patience for rolling my own
tests. I pretty much need to man up and start using JUnit or something
similar because this is pretty sinning tedious. And when it's tedious I'll
resist it until I have to. And I'll always have to, but I'm likely to turn
to embedded print statements instead. nono.

Anyway, the few tests I made in this time pass, not that it means much.
The fsa is clearly still broken. It seems like I'll have to test it
internally as I don't want to expose my innards for tests. (I am hazy on
which is responsible for hosting tests under a framework. All in due time.)

I'm also perceiving that fake_trie isn't a simple way to test lexer as
I'll need to work around its limitations. Maybe after I sleep on it.

Not really push worthy, but this workstation will soon be unavailable.
Worse, I haven't been able to find my usb memories, so I'm tied.

  • Participants
  • Parent commits 778f1ac

Comments (0)

Files changed (7)

 {
 	// serves as stub to test Lexer without a real FlatTrie
 	// use a var with a $, just for total sake
+	boolean keymode;
+	public FakeTrie( )
+	{
+		keymode = true; // for check flag()
+	}
 
 	@Override
 	public T_Flag determine_char( char to_validate )
 		case '3' :
 			return T_Flag.f_diff_flag;
 		default :
-			return T_Flag.saving;
+			return T_Flag.f_unseen;
 		}
 	}
 
 	@Override
 	public T_Flag check_flag( char a_flag )
 	{
+		keymode = ! keymode;
+		return ( keymode ) ? T_Flag.f_diff_flag : T_Flag.f_seen;
+	}
+
+	@Override
+	public void reveal_thyself( boolean overloading )
+	{
 		// TODO Auto-generated method stub
-		return null;
+		
 	}
 
 }
 		}
 	}
 
+	public void reveal_thyself( boolean n )
+	{
+		int low = 0;
+		int alph = first_char.length;
+		int upper = rest_stacked.lastIndexOf( Character.toString( end.charAt( 1 ) ) );
+		alph = ( alph > upper ) ? upper : alph;// CUT WHEN LONGER
+		upper = ( alph > upper ) ? alph : upper;// CUT WHEN LONGER
+		// should I be testing this?
+		String storage = rest_stacked.substring( 0, upper );
+		System.out.print( "\nFirst\t" );
+		for ( int a_search = low; a_search < alph; a_search++ )
+			System.out.print( first_char[ a_search ] );
+		System.out.print( "\nrest\t" );
+		for ( int a_search = low; a_search < alph; a_search++ )
+			System.out.print( storage.charAt( a_search ) );
+		System.out.print( "\nskip\t" );
+		for ( int a_search = low; a_search < alph; a_search++ )
+			sys_print_skip( a_search );
+		System.out.println( );
+		
+		low = alph;
+		System.out.print( "\nrest\t" );
+		for ( int a_search = low; a_search < upper; a_search++ )
+			System.out.print( storage.charAt( a_search ) );
+		System.out.print( "\nskip\t" );
+		for ( int a_search = low; a_search < upper; a_search++ )
+			sys_print_skip( a_search );
+	}
+
 	private char int_to_char( Integer number )
 	{
 		return number.toString().charAt( 0 );
 
 public enum L_Flag
 {
-	new_line, id_text, merge_to_id, between
+	new_line, id_text, between
 }
 	private String buffer;
 	private String debug;
 
-	public Lexer( char clients_epsilon, char signal_multi )
+	public Lexer( String valid_start, char clients_epsilon, char signal_multi )
 	{
-		transition_list = new FlatTrie( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$", "?*" );
+		transition_list = new FlatTrie( valid_start, "?*" );
 		empty = clients_epsilon;
 		multi = signal_multi;
 		state = L_Flag.new_line;
 		keymode = true;
 		debug = "";
 	}
-	
-	public Lexer( boolean test_mode )
-	{
-		transition_list = new FakeTrie();
-		empty = 'Z';
-		state = L_Flag.new_line;
-		multi = 'A';
-		keymode = true;
-		debug = "";
-	}
 
 	public void enter_key( char next )
 	{
 		}
 	}
 	
-	private char flag_to_debug( T_Flag nn )
+	char flag_to_debug( T_Flag nn )
 	{
 		switch ( nn )
 		{
 		return reported == T_Flag.f_unseen;
 	}
 
-	boolean starts_id( char dont_know )
+	private boolean starts_id( char dont_know )
 	{
 		return transition_list.in_alphabet( dont_know );
 	}
 
-	boolean ends_id( char dont_know )
+	private boolean ends_id( char dont_know )
 	{
 		return ! ( is_number( dont_know ) || transition_list.in_alphabet( dont_know ) );
 	}
 	{
 		transition_list.reveal_thyself();
 	}
-}
+
+	public void surrender_internals( boolean overloading )
+	{
+		transition_list.reveal_thyself( overloading );
+	}
+
+	public Lexer( boolean test_mode )
+	{
+		transition_list = new FakeTrie();
+		empty = 'Z';
+		state = L_Flag.new_line;
+		multi = 'A';
+		keymode = true;
+		debug = "";
+	}
+
+	// only sensible with testmode & fake trie
+	public boolean t_ch_ch_endl( )
+	{
+		
+		return false;
+	}
+
+	public boolean t_ch_ch_id( )
+	{
+		return false;
+	}
+
+	public boolean t_ch_ch_btwx( )
+	{
+		return false;
+	}
+
+	boolean t_matches_current_state( L_Flag from_out )
+	{
+		return state == from_out;
+	}
+
+	// only sensible with testmode & fake trie
+	public boolean test_enter_key() 
+	{
+		return false;
+	}
+}
+
+
+
+
+
+
+
+
+
+
+
 	static final int input_ind = key_ind + 1;
 	static final char nothing = '|';
 	static final char read_several = '&';
+	static final String fabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
 
 	// looks like, put you files in line, pipe is safe.
 	public static void main( String[] args )
 	{
 		//run( get_file_names( args[0] ) );
 		//run( args );
-		//run_tests();
-		run( new String[] { "InputFile1.txt", "arg.java" } );
+		run_tests();
+		//run( new String[] { "InputFile1.txt", "arg.java" } );
 		return;
 	}
 
 	static void run( String[] file_list )
 	{
-		Lexer java_lexer = new Lexer( nothing, read_several );
+		Lexer java_lexer = new Lexer( fabet, nothing, read_several );
 		save_key_words( file_list[ key_ind ], java_lexer );
 		flag_program( file_list[ input_ind ], java_lexer );
 		emit_saved_data( java_lexer );
 	static void run_tests()
 	{
 		TestSuite for_classes = new TestSuite();
-		for_classes.test_alphabet();
+		//for_classes.test_alphabet();
 		//for_classes.test_loader( "monkey.txt" ); // human checked quine, not a test
-		//for_classes.test_lexer();
+		for_classes.test_lexer();
 		//for_classes.test_trie();
-		for_classes.test_iterable_string();
+		//for_classes.test_iterable_string();
 	}
 }
 
 
 public abstract class Storage
 {
-	// here so I can test with a Trie stub
+	// here so I can test with a Trie stub,
+	// though it seems to have been premature functionality
 	public abstract T_Flag determine_char( char to_validate );
 
 	public abstract boolean in_alphabet( char bn );
-
-	public abstract void reveal_thyself();
 	
 	public abstract T_Flag check_flag( char a_flag );
+
+	public abstract void reveal_thyself();
+
+	public abstract void reveal_thyself( boolean overloading );
 }
 		this_file.close();
 	}
 
-	public void test_lexer( ) // FIX to proper tests
+	// current idea is constrained lang & input.
+	//later try dependency problem with fake trie 
+	public void test_lexer( )
 	{
 		System.out.println( " - Lexer" );
-		Lexer grammer_nazi = new Lexer( true );
-		// above creates with fake trie, not flat trie
-		grammer_nazi.ends_id( 'n' );
-		grammer_nazi.lex_char( 'd' );
+		char nil = '_';
+		char more = '^';
+		boolean no_complaints = true;
+		Lexer grammer_nazi = new Lexer( "axecbol", nil, more );
+		prep_lex_keys( grammer_nazi );
+		no_complaints = t_lex_endl_rej_bad( grammer_nazi, nil );
+
+		// add words? test the stuff inside?
+		IterableString var_1 = new IterableString( "ace " );
+		L_Flag id = L_Flag.id_text;
+		L_Flag btwx = L_Flag.between;
+		L_Flag line = L_Flag.new_line;
+		L_Flag[] st_should_pass = { id, id, id, btwx };
+		char flag_;
+		int nn = 0;
+		// has ending, so state should be between after
+		for ( Character let : var_1 )
+		{
+			flag_ = grammer_nazi.lex_char( let );
+			if ( ! grammer_nazi.t_matches_current_state( st_should_pass[nn] ) )
+			{
+				System.out.println( "lex: didnt move to between state" );
+				no_complaints = false;
+			}
+			nn++;
+		}
+
+		/*
+		for ( int ind = flags.length() -1; ind >= 0; ind-- )
+		{
+			if ( flags.charAt( ind ) != f_should_be.charAt( ind ) )
+			{
+				System.out.print( "lex: v_1, unexpected flag " );
+				System.out.printf( "e>%c r>%c\n",
+						f_should_be.charAt( ind ), flags.charAt( ind ) );
+				no_complaints = false;
+			}
+		}
+		unseen : 'N';
+		seen : '-';
+		diff_flag : 'F';*/
+		if ( no_complaints )
+			System.out.print( "seems okay" );
+		grammer_nazi.surrender_internals( no_complaints ); // just activating small version
+	}
+
+	private void prep_lex_keys( Lexer grammer_nazi )
+	{
+		IterableString key_1 = new IterableString( "axe " );
+		IterableString key_2 = new IterableString( "bool " );
+		// turns out that yak shaving may not have been totally useless
+		for ( Character in_str : key_1 )
+			grammer_nazi.enter_key( in_str );
+		for ( Character in_str : key_2 )
+			grammer_nazi.enter_key( in_str );
+		grammer_nazi.toggle_key_mode();
+	}
+
+	private boolean t_lex_endl_rej_bad( Lexer grammer_nazi, char nil )
+	{
+		char uu = grammer_nazi.lex_char( 'd' );
+		//if ( grammer_nazi.lex_char( 'd' ) != nil )
+		if ( uu != nil )
+		{
+			System.out.println( "lex: accepted non sigma-" + uu );
+			return false;
+		}
+		else if ( grammer_nazi.lex_char( '\n' ) != nil )
+		{
+			System.out.println( "lex: accepted preceeding endl" );
+			return false;
+		}
+		else if ( grammer_nazi.lex_char( '8' ) != nil )
+		{
+			System.out.println( "lex: accepted number" );
+			return false;
+		}
+		else
+			return true;
 	}
 
 	public void test_trie() // haha, pun