Skip to content

Commit

Permalink
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions vm/symbol_table.cpp
Original file line number Diff line number Diff line change
@@ -16,13 +16,8 @@ namespace rubinius {
SymbolTable::Kind SymbolTable::detect_kind(const char* str, size_t size) {
const char one = str[0];

// A constant begins with an uppercase letter.
if(one >= 'A' && one <= 'Z') {
// Make sure that the rest of it is only alphanumerics
for(size_t i = 1; i < size; i++) {
if((isalnum(str[i]) || str[i] == '_') == false)
return SymbolTable::Normal;
}
// Constants start with A-Z
if(isupper(one)) {
return SymbolTable::Constant;
}

16 changes: 16 additions & 0 deletions vm/test/test_symbol_table.hpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,22 @@ class TestSymbolTable : public CxxTest::TestSuite, public VMTest {
destroy();
}

void test_detect_kind_with_constant() {
const char *input = "Pettson";

SymbolTable::Kind kind = symbols->detect_kind(input, strlen(input));

TS_ASSERT_EQUALS(kind, SymbolTable::Constant);
}

void test_detect_kind_with_unicode_constant() {
const char *input = "Pettsonλ";

SymbolTable::Kind kind = symbols->detect_kind(input, strlen(input));

TS_ASSERT_EQUALS(kind, SymbolTable::Constant);
}

void test_lookup_with_c_str() {
Object* sym = symbols->lookup(state, std::string("unique"));
TS_ASSERT(sym->symbol_p());

0 comments on commit af157db

Please sign in to comment.