package com.torstling.tdop.fluid.json;

import com.torstling.tdop.fluid.Language;
import com.torstling.tdop.fluid.LanguageBuilder2;
import com.torstling.tdop.fluid.json.nodes.JsonNode;
import com.torstling.tdop.fluid.json.nodes.StringLiteralNode;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Created by alext on 2014-11-23.
 */
public class JsonTest {


    @Test
    public void test() {
        LanguageBuilder2<JsonNode> lb = new LanguageBuilder2<>();
        String stringLiteralPattern = "\"(\\w+)\"";
        Language<JsonNode> l = lb.newLevelToken().named("string_literal").matchesPattern(stringLiteralPattern)
                .standaloneParseAs((previous, match) -> {
                    String withinQuotationMarks = match.group(1);
                    return new StringLiteralNode(withinQuotationMarks);
                })
                .completeLanguage();
        JsonNode ast = l.getParser().parse("\"hello\"");
        assertEquals(new StringLiteralNode("hello"), ast);
    }

}

@@ -378,17 +378,16 @@
 Test %7B%0A%0A
-%0A
     @Tes
@@ -408,13 +408,168 @@
 oid 
-test(
+onlyText() %7B%0A        JsonNode ast = parse(%22%5C%22hello%5C%22%22);%0A        assertEquals(new StringLiteralNode(%22hello%22), ast);%0A    %7D%0A%0A    private JsonNode parse(String text
 ) %7B%0A
@@ -638,60 +638,8 @@
 ();%0A
-        String stringLiteralPattern = %22%5C%22(%5C%5Cw+)%5C%22%22;%0A
     
@@ -676,16 +676,41 @@
 newLevel
+()%0A                .start
 Token().
@@ -752,28 +752,20 @@
 ern(
-stringLiteralPattern
+%22%5C%22(%5C%5Cw*)%5C%22%22
 )%0A  
@@ -1022,30 +1022,22 @@
         
-JsonNode ast =
+return
  l.getPa
@@ -1053,77 +1053,11 @@
 rse(
-%22%5C%22hello%5C%22%22);%0A        assertEquals(new StringLiteralNode(%22hello%22), as
+tex
 t);%0A

Refactor JsonTest