Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ jobs:

- name: Run the default task
run: bundle exec rake

test-native:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run native tests
run: make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

/lib/yarp/yarp.*
test.rb
test-native/run-one
*.dSYM
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CFLAGS += -fsanitize=address -g
CFLAGS += -Wall

LSAN_OPTIONS = suppressions=test-native/LSan.supp:print_suppressions=0

test: test-native/run-one
LSAN_OPTIONS=$(LSAN_OPTIONS) ASAN_OPTIONS=detect_leaks=1 ./test-native/run-all.sh

test-native/run-one: test-native/run-one.c
$(CC) $(CFLAGS) $< -o $@

clean:
rm -f test-native/run-one

.PHONY: test clean
14 changes: 14 additions & 0 deletions bin/templates/token_type.c.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "token_type.h"
#include <string.h>

const char *
token_type_to_str(yp_token_type_t token_type)
Expand All @@ -12,3 +13,16 @@ token_type_to_str(yp_token_type_t token_type)
return "MAXIMUM";
}
}

yp_token_type_t
token_type_from_str(const char *s)
{
<%- tokens.each do |token| -%>
if (strcmp(s, "<%= token.name %>") == 0) {
return YP_TOKEN_<%= token.name %>;
}
<%- end -%>

// Fallback
return YP_TOKEN_INVALID;
}
1 change: 1 addition & 0 deletions bin/templates/token_type.h.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ typedef enum yp_token_type {
} yp_token_type_t;

const char *token_type_to_str(yp_token_type_t token_type);
yp_token_type_t token_type_from_str(const char *s);

#endif // YARP_TOKEN_TYPE_H
Loading