Skip to content

Commit

Permalink
add test for character encoding attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
domgold committed Oct 22, 2014
1 parent d604f9c commit 66e59c9
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 143 deletions.
19 changes: 18 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ http://asciidoctor.org[Asciidoctor] extension to format gherkin feature files in

You can use this extension to include your gherkin feature files in asciidoc in the form of sections, paragraphs, lists and tables.

The conversion is based on simple, customizable erb template.
The conversion is based on a simple, customizable erb template.

== Usage

Expand Down Expand Up @@ -100,3 +100,20 @@ would render like
| Scenario title1
| Scenario title2
|====

== Character Encoding

You can use attributes to define the encoding for reading the template file and the feature file.

You can define these attributes either in the block macro or at the document level.

template-encoding::
Used to read the custom template file if specified.
encoding::
Used to read the feature file.


.Defining feature encoding
----
gherkin::./simple.feature[encoding=UTF-8]
----
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def process parent, target, attributes
doc = parent.document
reader = parent.document.reader

print doc.attributes

if attributes.key?("template-encoding")
template_encoding = attributes["template-encoding"]
elsif doc.attributes.key?("template-encoding")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
package com.github.domgold.doctools.asciidoctor.gherkin;

import static org.asciidoctor.OptionsBuilder.options;
import static org.asciidoctor.AttributesBuilder.attributes;

import java.io.File;
import java.io.IOException;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
import org.junit.Before;
import org.junit.Test;

public class GherkinRubyBlockMacroTest {

@Test
public void test() throws IOException {
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
private Asciidoctor asciidoctor;
private Options options;
private File destinationDir;

@Before
public void initAsciidoctor() throws IOException {
asciidoctor = Asciidoctor.Factory.create();
GherkinExtensionRegistry reg = new GherkinExtensionRegistry();
reg.register(asciidoctor);

File destinationDir = new File("target/test-output");
destinationDir = new File("target/test-output");
if (!destinationDir.exists() && !destinationDir.mkdirs()) {
throw new IOException("could not create test-output dir");
}
Options options = options().toDir(destinationDir).safe(SafeMode.UNSAFE)
options = options().toDir(destinationDir).safe(SafeMode.UNSAFE)
.get();
asciidoctor.convertFile(new File(
"src/test/resources/simple_specs_example.adoc"), options);
}

@Test
public void simpleTest() {
asciidoctor.convertFile(new File("src/test/resources/simple_specs_example.adoc"), options);
}

@Test
public void complexTest() {
asciidoctor.convertFile(new File(
"src/test/resources/complex_specs_example.adoc"), options);
}

@Test
public void testWithUTF8FeatureBlockMacroAttributeANSI() {
options.setAttributes(attributes().attribute("encoding", "iso-8859-1").get());
asciidoctor.convertFile(new File("src/test/resources/block_macro_encoding_attribute_ANSI.adoc"), options);
}

@Test
public void testWithUTF8FeatureBlockMacroAttributeUTF8() {
//UTF-8 is default
//options.setAttributes(attributes().attribute("encoding", "UTF-8").get());
asciidoctor.convertFile(new File("src/test/resources/block_macro_encoding_attribute_UTF8.adoc"), options);
}

@Test(expected=gherkin.lexer.LexingError.class)
public void testBlockMacroWithWrongEncodingAttributeFails() {
options.setAttributes(attributes().attribute("encoding", "UTF-8").get());
asciidoctor.convertFile(new File("src/test/resources/block_macro_encoding_attribute_ANSI.adoc"), options);
}
}
9 changes: 9 additions & 0 deletions src/test/resources/block_macro_encoding_attribute_ANSI.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= Example simple

== Mes fonctionnalités

gherkin::./french_ANSI.feature[]

gherkin::./french_UTF8.feature[encoding=UTF-8]

gherkin::./french_ANSI.feature[encoding=iso-8859-1]
9 changes: 9 additions & 0 deletions src/test/resources/block_macro_encoding_attribute_UTF8.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= Simple specs example

== My features

gherkin::./french_UTF8.feature[]

gherkin::./french_UTF8.feature[encoding=UTF-8]

gherkin::./french_ANSI.feature[encoding=iso-8859-1]
10 changes: 10 additions & 0 deletions src/test/resources/french_ANSI.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# language: fr
Fonctionnalité: Une fonctionnalité simple
Voici la description de la fonctionnalité.

Contexte: Le contexte
Etant donné une étape simple

Scénario: Le titre du scénario
Quand j'inclus le fichier gherkin dans le document asciidoc
Alors les étapes du scénario apparaissent sous forme de liste.
10 changes: 10 additions & 0 deletions src/test/resources/french_UTF8.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# language: fr
Fonctionnalité: Une fonctionnalité simple
Voici la description de la fonctionnalité.

Contexte: Le contexte
Etant donné une étape simple

Scénario: Le titre du scénario
Quand j'inclus le fichier gherkin dans le document asciidoc
Alors les étapes du scénario apparaissent sous forme de liste.
130 changes: 0 additions & 130 deletions src/test/resources/selfcare.feature

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/resources/simple_specs_example.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
gherkin::./simple.feature[]

gherkin::./simple2.feature[]

gherkin::./selfcare.feature[]

0 comments on commit 66e59c9

Please sign in to comment.