locale_test.anubis 5.88 KB

 *Project*                             The Anubis Project
   
 *Title*                     		 Tests of implementation of 
 	 								Locale Language Library (L3)
   
 *Copyright*                     Copyright (c) David René 2006. 


   

 *Created* 2006 01 13
 *Author*  David René
 *Status*  Beta 1

read locale/L3.anubis

 *descirption*
 In this function we fill the database with test symbol such as :

  * hello
  * ok
  * apply
  * cancel
  * help
  
public define List(L3Symbol)
   symbols_test 
     =
   [l3Symbol("hello"  , "polite"    , "hello text"),
    l3Symbol("ok"     , "interface" , "ok text"),
    l3Symbol("apply"  , "interface" , "apply text"),
    l3Symbol("cancel" , "interface" , "cancel text"),
    l3Symbol("help"   , "interface" , "help text")
    ].

public define List(L3Text)
   english_text 
     =
   [l3Text("hello"  , "hello"   ),
    l3Text("ok"     , "ok"      ),
    l3Text("apply"  , "apply"   ),
    l3Text("cancel" , "cancel"  ),
    l3Text("help"   , "help"    )
    ].

public define List(L3Text)
   french_text 
     =
   [l3Text("hello"  , "bonjour"   ),
    l3Text("ok"     , "ok"        ),
    l3Text("apply"  , "appliquer" ),
    l3Text("cancel" , "annuler"   ),
    l3Text("help"   , "aide"      )
    ].

public define List(L3Text)
   chinese_text 
     =
   [l3Text("hello"  , "你好"   ),
    l3Text("ok"     , "好"        ),
    l3Text("apply"  , "应用" ),
    l3Text("cancel" , "取消"   ),
    l3Text("help"   , "帮助"      )
    ].

public define List(L3Text)
   japanese_text 
     =
   [l3Text("hello"  , "こにちは"   ),
    l3Text("ok"     , "あい"        ),
    l3Text("apply"  , "是認する" ),
    l3Text("cancel" , "キャンセル"   ),
    l3Text("help"   , "助け"      )
    ].

define Bool locale_test_put_symbols(L3 l3base, List(L3Symbol) symbols) =
  if symbols is
  {
    [] then true,
    [ h .  t ] then if h is l3Symbol(name, chapter, description) then
        if put_symbol(l3base, name, chapter, description) is
        {
          false then print("Can't add symbol " + name + "  in chapter " + chapter + "\n");
                     locale_test_put_symbols(l3base, t),
          true  then print("Add OK of symbol " + name + "  in chapter " + chapter + "\n");
                     locale_test_put_symbols(l3base, t)
        }
  }.

define Bool locale_test_put_texts(L3 l3base, String language, List(L3Text) text_list) =
  if text_list is
  {
    [] then true,
    [ h .  t ] then if h is l3Text(symbol, text) then
        if put_text(l3base, symbol, language, text) is
        {
          false then print("Can't add ["+ language +"] text " + text + "  in symbol " + symbol + "\n");
                     locale_test_put_texts(l3base, language, t),
          true  then print("Add OK of ["+ language +"] text " + text + "  in symbol " + symbol + "\n");
                     locale_test_put_texts(l3base, language, t)
        }
  }.

global define One locale_test (List (String) args) =
  
  if l3_base_exists("locale_test", "symb") is
  {
    false then
      if l3_create_base("locale_test", "symb") is
      {
        false then print("can't create locale_test database"),
        true  then print("locale_test created\n");
        if l3_load_base("locale_test") is
        {
          failure then print("can't load database \"locale_test\" "); unique,
          success(L3 locale) then 
          if locale_test_put_symbols(locale, symbols_test) is
          {
            false then print("Can't add symbols")
            true then print("Symbols added"),
          }
        }
      }
    true then 
      if l3_load_base("locale_test") is
      {
        failure then print("can't load database \"locale_test\" "); unique,
        success(L3 locale) then 
          print("locale_test database loaded\n");
          if get_symbol(locale, "hello") is
          {
            failure then print("Can't get hello symbol"); unique
            success(helloSymbol) then 
            if helloSymbol is l3Symbol( name, chapter, desc) then
              print("symbol      : " + name + "\n");
              print("chapter     : " + chapter +"\n");
              print("description : " + desc + "\n")
          }
      }
  };
  //TEST OF ENGLISH DATABASE 
  if l3_load_base("locale_test") is
  {
    failure then print("can't load database \"locale_test\" "); unique,
    success(L3 locale) then 
    if l3_add_language(locale, "en", (Int32)0, false) is
    {
      failure then print("can't load database \"locale_test\" "); unique,
      success(_) then
      if locale_test_put_texts(locale, "en", english_text) is
      {
        false then print("Can't add english text\n")
        true then print("English text added\n"),
      }    
    };
    if l3_add_language(locale, "fr", (Int32)0, false) is
    {
      failure then print("can't load database \"locale_test\" "); unique,
      success(_) then
      if locale_test_put_texts(locale, "fr", french_text) is
      {
        false then print("Can't add french text\n")
        true then print("French text added\n"),
      }    
    };
    if l3_add_language(locale, "zho", (Int32)0, false) is
    {
      failure then print("can't load database \"locale_test\" "); unique,
      success(_) then
      if locale_test_put_texts(locale, "zho", chinese_text) is
      {
        false then print("Can't add chinese text\n")
        true then print("Chinese text added\n"),
      }    
    };
    if l3_add_language(locale, "ja", (Int32)0, false) is
    {
      failure then print("can't load database \"locale_test\" "); unique,
      success(_) then
      if locale_test_put_texts(locale, "ja", japanese_text) is
      {
        false then print("Can't add japanese text\n")
        true then print("Japanese text added\n"),
      }    
    };
    with locale = l3_set_default(locale, "en"),
    with locale = l3_set_current(locale, "fr"),
    print("hello in fr is " + get_text(locale, "hello") +"\n");
    forget(map((String s) |-> print(s+" \n"), l3_get_all_dic))

  }.