示例#1
0
/**
 * test_symbol_flyweight:
 * @fn test_symbol_unicode
 * Tests whether compilerkit_symbol_new in CompilerKitSymbol struct allocates new space only for unique symbols.
 * @pre None
 * @param None
 * @return void
 */
void test_symbol_flyweight (void)
{
    CompilerKitSymbol *symbol1, *symbol2, *symbol3;
    
    g_test_message ("Testing Symbol unicode");
    g_test_timer_start ();
    
    /** @todo Test here  */
    symbol1 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('a'));
    symbol2 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('b'));
    symbol3 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('a'));

    /* Symbol b is distinct from Symbol a */
    g_assert (symbol2 != symbol3);
    g_assert (symbol2 != symbol1);

    /* The pointer to Symbol('a') should equal the pointer to Symbol('a').
       This of course, would make Ayn Rand proud ;-) */
    g_assert (symbol1 == symbol3);

    g_object_unref(symbol1);
    g_object_unref(symbol2);
    g_object_unref(symbol3);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
示例#2
0
/* ToNfa symbol. */
static GObject *to_nfa_symbol (CompilerKitVisitor *self, GObject *obj)
{
    CompilerKitSymbol *symbol;
    g_assert(COMPILERKIT_IS_SYMBOL(obj));
    
    symbol = COMPILERKIT_SYMBOL (obj);
    
    compilerkit_symbol_get_symbol(symbol);
    return NULL;
}
/* StringBuilder symbol. */
static GObject *string_builder_symbol (CompilerKitVisitor *self, GObject *obj)
{
    CompilerKitSymbol *symbol;
    GString *str = (GString *) compilerkit_visitor_get_state(self);
    g_assert(COMPILERKIT_IS_SYMBOL(obj));
    
    symbol = COMPILERKIT_SYMBOL (obj);
    
    g_string_append_unichar(str, compilerkit_symbol_get_symbol(symbol));
    return NULL;
}
示例#4
0
/**
 * compilerkit_symbol_dispose:
 * @fn compilerkit_symbol_dispose
 * Reverse what compilerkit_symbol_init allocated.
 * @pre GObject is not NULL.
 * @param GObject* An object to dispose.
 * @return void
 */
static void
compilerkit_symbol_dispose (GObject* object)
{
  CompilerKitSymbol *self = COMPILERKIT_SYMBOL (object);
  CompilerKitSymbolPrivate* priv;

  priv = COMPILERKIT_SYMBOL_GET_PRIVATE (self);
  
  /** @todo Deallocate memory as necessary */

  G_OBJECT_CLASS (compilerkit_symbol_parent_class)->dispose (object);
}
示例#5
0
/**
 * test_symbol_unicode:
 * @fn test_symbol_unicode
 * Tests compilerkit_symbol_new in CompilerKitSymbol struct for the ability to deal with Unicode (specifically, UTF-8).
 * @pre None
 * @param None
 * @return void
 */
void test_symbol_unicode (void)
{
    CompilerKitSymbol *symbol;
    g_test_message ("Testing Symbol unicode");
    g_test_timer_start ();
   
    gunichar ch = g_utf8_get_char("台");

    symbol = COMPILERKIT_SYMBOL (compilerkit_symbol_new(ch));

    g_assert(compilerkit_symbol_get_symbol (symbol) == ch /*'台'*/ );

    g_object_unref(symbol);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
示例#6
0
/**
 * compilerkit_symbol_new:
 * @fn compilerkit_symbol_new
 * @memberof CompilerKitSymbol
 * Construct a CompilerKitSymbol instance.
 * @pre None
 * @param None
 * @return A new CompilerKitSymbol struct, cast to GObject*.
 */
GObject *compilerkit_symbol_new (char symbol)
{
	CompilerKitSymbol *result = COMPILERKIT_SYMBOL (g_object_new (COMPILERKIT_TYPE_SYMBOL, NULL));
    result->priv->symbol = symbol;
    return G_OBJECT(result);
}