home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / envsof20 / source / syntax / test_language.c < prev   
Encoding:
C/C++ Source or Header  |  1999-08-28  |  3.1 KB  |  113 lines

  1. /* test_language.c -- Test functions in language.c
  2.  *
  3.  * Copyright 1999 Thomas Aglassinger and others, see file "forum.txt"
  4.  */
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <assert.h>
  8.  
  9. #include "keyword.h"
  10. #include "language.h"
  11.  
  12. extern char is_normal[256];
  13. extern char is_alpha[256];
  14. extern char is_numeric[256];
  15. extern char is_upper[256];
  16. extern char is_lower[256];
  17.  
  18. void test_word_types(char *text, struct keyword_info *info)
  19. {
  20.    ULONG indent = 0;
  21.    ULONG length = strlen(text);
  22.    ULONG word_start = 0;
  23.    ULONG word_end = 0;
  24.    int was_abnormal = 1;
  25.  
  26.    printf("test_word_types(\"%s\")\n", text);
  27.    for (indent = 0; indent < length; indent++)
  28.    {
  29.       if (was_abnormal)
  30.       {
  31.          if (is_normal[text[indent]]) {
  32.             was_abnormal = 0;
  33.             word_start = indent;
  34.          }
  35.       }
  36.       else if (!is_normal[text[indent]]) {
  37.          char buffer;
  38.  
  39.          word_end = indent;
  40.  
  41.          buffer = text[word_end];
  42.          text[indent] = 0;
  43.          printf("  %2ld-%2d: \"%s\"\n", word_start, word_end-1, &text[word_start]);
  44.          text[word_end] = buffer;
  45.  
  46.          printf("         %s\n",
  47.                 get_word_type_text(get_word_type(text, word_start, word_end, info)));
  48.  
  49.          word_start = indent;
  50.          was_abnormal = 1;
  51.       }
  52.    }
  53. }
  54.  
  55. void test_is_reserved_word(char *text, ULONG word_start, ULONG word_end, int is, struct keyword_info *info)
  56. {
  57.    int actual_is;
  58.  
  59.    printf("is_reserved_word(\"%s\", %ld,%ld)\n", text, word_start, word_end);
  60.    actual_is = is_reserved_word(text, word_start, word_end, info);
  61.    printf("  -> %d\n", actual_is);
  62.    assert(actual_is == is);
  63. }
  64.  
  65. int main(int argc, char *argv[])
  66. {
  67.    struct keyword_info *info;
  68.  
  69.    setup_char_array();
  70.    create_keyword_list();
  71.    info = keywords_of("golded:add-ons/eiffel/syntax/eiffel.keyword");
  72.  
  73.    if (info == NULL) {
  74.       printf("no keyword info\n");
  75.    } else {
  76.       STRPTR *word = info->word;
  77.       ULONG  word_count = info->word_count;
  78.  
  79.       printf("%d reserved words: \"%s\"..\"%s\"\n", word_count,
  80.              word[0], word[word_count - 1]);
  81.  
  82.       printf("word_type(is)   = %d\n", get_word_type("is", 0, 2, info));
  83.       printf("word_type(Sepp) = %d\n", get_word_type("Sepp", 0, 4, info));
  84.       printf("is_alpha: a b 1 _ !   ä\n"
  85.              "          %d %d %d %d %d %d %d\n",
  86.              is_alpha['a'],
  87.              is_alpha['b'],
  88.              is_alpha['1'],
  89.              is_alpha['_'],
  90.              is_alpha['!'],
  91.              is_alpha[' '],
  92.              is_alpha[(unsigned char) 'ä']);
  93.       printf("fsc(index,indexing) = %d\n", fstrncmp("index", "indexing", 5));
  94.       printf("fsc(class,class) = %d\n", fstrncmp("class", "class", 5));
  95.  
  96. #if 1
  97.       test_is_reserved_word("sepp", 0, 4, 0, info);
  98.       test_is_reserved_word("old stuff", 0, 3, 1, info);
  99.       test_is_reserved_word("alias", 0, 5, 1, info);
  100.       test_is_reserved_word("index", 0, 5, 0, info);
  101.       test_is_reserved_word("pri", 0, 3, 0, info);
  102.       test_is_reserved_word("xor", 0, 3, 1, info);
  103.  
  104.       test_word_types("  sepp := old sepp+Ranz_hanz;   "
  105.                       "  class HUGO feature is nothing;", info);
  106. #endif
  107.    }
  108.    dispose_keyword_list();
  109.  
  110.    return 0;
  111. }
  112.  
  113.