From 28dc452853f1cc842040d8f74c303a9c4a432d08 Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Thu, 20 Apr 2017 08:29:12 +0200 Subject: [PATCH] added some corner cases to content.go generation tests --- .../code-generator/generator/heuristics.go | 4 +- .../generator/test_files/content.gold | 97 ++++++++++++++++--- .../generator/test_files/heuristics.test.rb | 47 +++++++++ 3 files changed, 134 insertions(+), 14 deletions(-) diff --git a/internal/code-generator/generator/heuristics.go b/internal/code-generator/generator/heuristics.go index 077b4b8..f0ddedf 100644 --- a/internal/code-generator/generator/heuristics.go +++ b/internal/code-generator/generator/heuristics.go @@ -299,7 +299,7 @@ func getHeuristics(line string) []*heuristic { } if reg != "" { - reg = convToValidRegexp(reg) + reg = convertToValidRegexp(reg) heuristics = append(heuristics, &heuristic{Regexp: reg}) } } @@ -327,7 +327,7 @@ func replaceRegexpVariables(reg string) string { return repl } -func convToValidRegexp(reg string) string { +func convertToValidRegexp(reg string) string { // example: `/^(\s*)(])`) + h_CPlusPlus_Matcher_0 = regexp.MustCompile(`(?m)^\s*#\s*include <(cstdint|string|vector|map|list|array|bitset|queue|stack|forward_list|unordered_map|unordered_set|(i|o|io)stream)>`) + h_CPlusPlus_Matcher_1 = regexp.MustCompile(`(?m)^\s*template\s*<`) + h_CPlusPlus_Matcher_2 = regexp.MustCompile(`(?m)^[ \t]*try`) + h_CPlusPlus_Matcher_3 = regexp.MustCompile(`(?m)^[ \t]*catch\s*\(`) + h_CPlusPlus_Matcher_4 = regexp.MustCompile(`(?m)^[ \t]*(class|(using[ \t]+)?namespace)\s+\w+`) + h_CPlusPlus_Matcher_5 = regexp.MustCompile(`(?m)^[ \t]*(private|public|protected):$`) + h_CPlusPlus_Matcher_6 = regexp.MustCompile(`(?m)std::\w+`) + lsp_CommonLisp_Matcher_0 = regexp.MustCompile(`(?mi)^\s*\((defun|in-package|defpackage) `) + lsp_NewLisp_Matcher_0 = regexp.MustCompile(`(?m)^\s*\(define `) + lisp_CommonLisp_Matcher_0 = regexp.MustCompile(`(?mi)^\s*\((defun|in-package|defpackage) `) + lisp_NewLisp_Matcher_0 = regexp.MustCompile(`(?m)^\s*\(define `) + md_Markdown_Matcher_0 = regexp.MustCompile(`(?mi)(^[-a-z0-9=#!\*\[|>])|<\/`) + md_Markdown_Matcher_1 = regexp.MustCompile(`(?m)^$`) + md_GCCmachinedescription_Matcher_0 = regexp.MustCompile(`(?m)^(;;|\(define_)`) + ms_Groff_Matcher_0 = regexp.MustCompile(`(?mi)^[.'][a-z][a-z](\s|$)`) + mod_XML_Matcher_0 = regexp.MustCompile(`(?m)/.match(data) || + /^\s*template\s*])|<\//i.match(data) || data.empty? + Language["Markdown"] + elsif /^(;;|\(define_)/.match(data) + Language["GCC machine description"] + else + Language["Markdown"] + end + end + disambiguate ".ms" do |data| if /^[.'][a-z][a-z](\s|$)/i.match(data) Language["Groff"] @@ -42,3 +81,11 @@ Language["IDL"] end end + + disambiguate ".rpy" do |data| + if /(^(import|from|class|def)\s)/m.match(data) + Language["Python"] + else + Language["Ren'Py"] + end + end