------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- test_str_cursor.sa:
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>

class TEST_STR_CURSOR is
   include TEST;
 
   cursor(s: STR): STR_CURSOR is return #STR_CURSOR(s) end;
   
   main is
      class_name("STR_CURSOR");
      test_str ::= "This is a test\n"+
	    "Does a reasonable job\n"
	    "to some extent";
      sc ::= cursor(test_str);
      test("current line str",sc.current_line_str,"This is a test");
      test("current loc str", sc.current_loc_str('^'),"^");      
      discard ::= sc.get_up_to('\n');
      sc.advance_one_char;	-- Over the newline
      sc.advance_one_char;
      test("current line str",sc.current_line_str,"Does a reasonable job");
      test("current loc str",sc.current_loc_str('^')," ^");
      test_str2 ::= "This ( is a (test) of ) (nes(ti)ng) z";
      sc := cursor(test_str2);
      disc3 ::= sc.get_up_to('(');
      test("nesting",sc.get_block('(',')'),"( is a (test) of )");
      disc4 ::= sc.get_up_to('(');
      sc.skip_block('(',')');
      sc.advance_one_char;
      test("skip block",sc.get_char.str,"z");
      testcom ::= "test -- of comments\n"
	    "which #should not be printed\n"
	    "do various types";
      sc := cursor(testcom);
      sc.set_comment_syntax('-','-');
      wrd ::= sc.get_word;
      sc.skip_space;
      test("skip comments",sc.get_word,"which");
      sc.set_comment_syntax('#');
      sc.skip_space;
      test("skip_comments",sc.get_word,"do");
      sc := cursor("Another Test string");
      test("get_str_upto_cut",sc.get_str_upto_cut("Te"),"Anoth");
      sc := cursor("a/test/of");
      r1: FLIST{STR} := #(|"a","test","of"|);
      test("get_str_upto",sc.split('/').str,r1.str);
      sc := cursor("a/test/of/");
      test("get_str_upto",sc.split('/').str,r1.str);
      test("get_int",cursor("0xFE").int,254); 
      test("get_int",cursor("0b1101").int,13);
      test("get_int",cursor("0o47").int,39);
      test("get_int",cursor("1234").int,1234);
      test("get_int",cursor("12345678").int,12345678);
      test("get_int",cursor("0").int,0);
      test("get_int",cursor("").int,0);
      test("get_int",cursor("-10023").int,-10023);
      test("get_flt",cursor("123.45e-2").get_flt,123.45e-2);
      finish;
   end;

end;
--------------------------------------------------------------------------
