aboutsummaryrefslogtreecommitdiff
path: root/parser_inline_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-10-31 04:01:41 +0700
committerShulhan <m.shulhan@gmail.com>2020-10-31 04:01:41 +0700
commit45e1e54c75bda5591cf02ea8bc899a8150b3dcfc (patch)
tree2119c2076af4dc4d738064946a3e7995538218bc /parser_inline_test.go
parentee78188ea91964725f58cc3d8c472cc9ab2f5c36 (diff)
downloadasciidoctor-go-45e1e54c75bda5591cf02ea8bc899a8150b3dcfc.tar.xz
all: implement parser for block anchor and inline anchor
Diffstat (limited to 'parser_inline_test.go')
-rw-r--r--parser_inline_test.go131
1 files changed, 109 insertions, 22 deletions
diff --git a/parser_inline_test.go b/parser_inline_test.go
index 30a88da..5a7228d 100644
--- a/parser_inline_test.go
+++ b/parser_inline_test.go
@@ -30,8 +30,8 @@ func TestParserInline_do(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -80,8 +80,8 @@ func TestParserInline_parseFormat(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -122,8 +122,95 @@ func TestParserInline_parseFormatUnconstrained(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // container.debug(0)
+
+ got := buf.String()
+ test.Assert(t, c.content, c.exp, got, true)
+ }
+}
+
+func TestParserInline_parseInlineID(t *testing.T) {
+ cases := []struct {
+ content string
+ exp string
+ isForToC bool
+ }{{
+ content: `[[A]] B`,
+ exp: `<a id="A"></a> B`,
+ }, {
+ content: `[[A]] B`,
+ exp: ` B`,
+ isForToC: true,
+ }, {
+ content: `[[A] B`,
+ exp: `[[A] B`,
+ }, {
+ content: `[A]] B`,
+ exp: `[A]] B`,
+ }, {
+ content: `[[A ]] B`,
+ exp: `[[A ]] B`,
+ }, {
+ content: `[[ A]] B`,
+ exp: `[[ A]] B`,
+ }, {
+ content: `[[A B]] C`,
+ exp: `[[A B]] C`,
+ }}
+
+ var buf bytes.Buffer
+ for _, c := range cases {
+ buf.Reset()
+
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, c.isForToC)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // container.debug(0)
+
+ got := buf.String()
+ test.Assert(t, c.content, c.exp, got, true)
+ }
+}
+
+func TestParserInline_parseInlineIDShort(t *testing.T) {
+ cases := []struct {
+ content string
+ exp string
+ }{{
+ content: `[#A]#B#`,
+ exp: `<span id="A">B</span>`,
+ }, {
+ content: `[#A]#B`,
+ exp: `[#A]#B`,
+ }, {
+ content: `[#A]B#`,
+ exp: `[#A]B#`,
+ }, {
+ content: `[#A ]#B#`,
+ exp: `[#A ]#B#`,
+ }, {
+ content: `[# A]# B#`,
+ exp: `[# A]# B#`,
+ }, {
+ content: `[#A B]# C#`,
+ exp: `[#A B]# C#`,
+ }}
+
+ var buf bytes.Buffer
+ for _, c := range cases {
+ buf.Reset()
+
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -156,8 +243,8 @@ You can find Linux everywhere these days!`,
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -194,8 +281,8 @@ func TestParserInline_parsePassthrough(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -238,8 +325,8 @@ func TestParserInline_parsePassthroughDouble(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -288,8 +375,8 @@ func TestParserInline_parsePassthroughTriple(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -335,8 +422,8 @@ func TestParserInline_parseQuote(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -373,8 +460,8 @@ func TestParserInline_parseSubscsript(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -411,8 +498,8 @@ func TestParserInline_parseSuperscript(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}
@@ -458,8 +545,8 @@ func TestParserInline_parseURL(t *testing.T) {
for _, c := range cases {
buf.Reset()
- container := parseInlineMarkup([]byte(c.content))
- err := container.toHTML(_testDoc, _testTmpl, &buf)
+ container := parseInlineMarkup(_testDoc, []byte(c.content))
+ err := container.toHTML(_testDoc, _testTmpl, &buf, false)
if err != nil {
t.Fatal(err)
}