Permalink
Browse files

Update easy symbol document, data, and test case

  • Loading branch information...
1 parent e14be1e commit 0a96e01d0cc7a099e9bca553bffbecc72a493c96 @czchen czchen committed Oct 23, 2012
Showing with 107 additions and 60 deletions.
  1. +21 −21 data/swkb.dat
  2. +12 −2 doc/libchewing.texi
  3. +74 −37 test/test-easy-symbol.c
View
@@ -1,26 +1,26 @@
-q
+Q
W 〕
A 【
S 】
Z 《
X 》
-e
-r
-d
-f
-c
-v
-t
-y
-g
-h
-b
-n
-u
-i
-o ×
-p ÷
-j
-k
-l Orz
-m
+E
+R
+D
+F
+C
+V
+T
+Y
+G
+H
+B
+N
+U
+I
+O ×
+P ÷
+J
+K
+L Orz
+M
View
@@ -733,11 +733,21 @@ This function returns the auto shift cursor setting.
@end deftypefun
@deftypefun void chewing_set_easySymbolInput (ChewingContext *@var{ctx}, int @var{mode})
-@strong{TODO}: What does this mean?
+This function sets the current normal/easy symbol mode. In easy symbol mode,
+the key be will changed to its related easy symbol in @file{swkb.dat}. The
+format of @file{swkb.dat} is key symble pair per line. The valid value of key
+is [0-9A-Z]. The lower case character in key will be changed to upper case when
+loading @file{swkb.dat}. However, in easy symbol mode, only [0-9A-Z] are
+accepted.
+
+The @var{mode} argument is @code{0} for normal mode or @code{other} for easy
+symbol mode.
+
+@strong{TODO}: Need a macro for @var{mode}.
@end deftypefun
@deftypefun int chewing_get_easySymbolInput (ChewingContext *@var{ctx})
-@strong{TODO}: What does this mean?
+This function gets the current easy symbol mode.
@end deftypefun
@deftypefun void chewing_set_phraseChoiceRearward (ChewingContext *@var{ctx}, int @var{mode})
View
@@ -20,41 +20,57 @@
#include "test_harness.h"
typedef struct {
- char token;
+ char * token;
char * expected;
} TestData;
-void test_type_easy_symbol()
+static const TestData EASY_SYMBOL[] = {
+ { .token = "Q", .expected = "" },
+ { .token = "W", .expected = "" },
+ { .token = "A", .expected = "" },
+ { .token = "S", .expected = "" },
+ { .token = "Z", .expected = "" },
+ { .token = "X", .expected = "" },
+ { .token = "E", .expected = "" },
+ { .token = "R", .expected = "" },
+ { .token = "D", .expected = "" },
+ { .token = "F", .expected = "" },
+ { .token = "C", .expected = "" },
+ { .token = "V", .expected = "" },
+ { .token = "T", .expected = "" },
+ { .token = "Y", .expected = "" },
+ { .token = "G", .expected = "" },
+ { .token = "H", .expected = "" },
+ { .token = "B", .expected = "" },
+ { .token = "N", .expected = "" },
+ { .token = "U", .expected = "" },
+ { .token = "I", .expected = "" },
+ { .token = "O", .expected = "×" },
+ { .token = "P", .expected = "÷" },
+ { .token = "J", .expected = "" },
+ { .token = "K", .expected = "" },
+ { .token = "L", .expected = "Orz" },
+ { .token = "M", .expected = "" },
+};
+
+static const TestData CHINESE[] = {
+ { .token = "hk4g4", .expected = "測試" },
+};
+
+void verify_test_data( ChewingContext *ctx, const TestData *data )
{
- static const TestData DATA[] = {
- { .token = 'Q', .expected = "" },
- { .token = 'W', .expected = "" },
- { .token = 'A', .expected = "" },
- { .token = 'S', .expected = "" },
- { .token = 'Z', .expected = "" },
- { .token = 'X', .expected = "" },
- { .token = 'E', .expected = "" },
- { .token = 'R', .expected = "" },
- { .token = 'D', .expected = "" },
- { .token = 'F', .expected = "" },
- { .token = 'C', .expected = "" },
- { .token = 'V', .expected = "" },
- { .token = 'T', .expected = "" },
- { .token = 'Y', .expected = "" },
- { .token = 'G', .expected = "" },
- { .token = 'H', .expected = "" },
- { .token = 'B', .expected = "" },
- { .token = 'N', .expected = "" },
- { .token = 'U', .expected = "" },
- { .token = 'I', .expected = "" },
- { .token = 'O', .expected = "×" },
- { .token = 'P', .expected = "÷" },
- { .token = 'J', .expected = "" },
- { .token = 'K', .expected = "" },
- { .token = 'L', .expected = "Orz" },
- { .token = 'M', .expected = "" },
- };
+ for ( int i = 0; i < strlen(data->token); ++i ) {
+ chewing_handle_Default( ctx, data->token[i] );
+ }
+ chewing_handle_Enter( ctx );
+ char *buf = chewing_commit_String( ctx );
+ ok( !strcmp( buf, data->expected ), "output shall be expected value" );
+ chewing_free( buf );
+}
+
+void test_type_easy_symbol()
+{
putenv( "CHEWING_PATH=" CHEWING_DATA_PREFIX );
putenv( "CHEWING_USER_PATH=" TEST_HASH_DIR );
@@ -66,21 +82,42 @@ void test_type_easy_symbol()
chewing_set_maxChiSymbolLen( ctx, 16 );
chewing_set_easySymbolInput( ctx, 1 );
- for ( int i = 0; i < sizeof( DATA ) / sizeof( DATA[0] ); ++i ) {
- chewing_handle_Default( ctx, DATA[i].token );
- chewing_handle_Enter( ctx );
- char *buf = chewing_commit_String( ctx );
- ok( strcmp( buf, DATA[i].expected ) == 0,
- "output shall be expected easy symbol" );
- chewing_free( buf );
+ for ( int i = 0; i < sizeof( EASY_SYMBOL ) / sizeof( EASY_SYMBOL[0] );
+ ++i ) {
+ verify_test_data( ctx, &EASY_SYMBOL[i] );
}
chewing_delete( ctx );
chewing_Terminate();
}
+void test_mode_change()
+{
+ putenv( "CHEWING_PATH=" CHEWING_DATA_PREFIX );
+ putenv( "CHEWING_USER_PATH=" TEST_HASH_DIR );
+
+ chewing_Init( NULL, NULL );
+
+ ChewingContext *ctx = chewing_new();
+ ok( ctx, "chewing_new shall not return NULL" );
+
+ chewing_set_maxChiSymbolLen( ctx, 16 );
+
+ verify_test_data( ctx, &CHINESE[0] );
+
+ chewing_set_easySymbolInput( ctx, 1 );
+ verify_test_data( ctx, &EASY_SYMBOL[0] );
+
+ chewing_set_easySymbolInput( ctx, 0 );
+ verify_test_data( ctx, &CHINESE[0] );
+
+ chewing_delete( ctx );
+ chewing_Terminate();
+}
+
int main()
{
test_type_easy_symbol();
+ test_mode_change();
return exit_status();
}

0 comments on commit 0a96e01

Please sign in to comment.