str_cursor_test.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- test_str_cursor.sa: 
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: str_cursor_test.sa,v 1.2 1996/04/09 10:06:34 borisv Exp $
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.


class TEST_STR_CURSOR

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;