From c3229ea55bcccba5b6217da2c84ace2ba3194a8a Mon Sep 17 00:00:00 2001 From: Dmitrii Malinovskii <109508884+wdipax@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:17:34 +0400 Subject: [PATCH] feat: Support more natural languages for the features. (#120) Co-authored-by: Dmitrii Malinovskii --- .gitignore | 1 + README.md | 9 +- internal/app/app.feature | 91 +++++++++---- internal/app/app.go | 32 ++++- internal/app/app_test.go | 126 +++++++++++++++++- internal/app/generator.go | 2 + internal/app/language.go | 67 ++++++++++ internal/app/testdata/english.feature | 7 + .../app/testdata/english.sample.en.feature | 7 + internal/app/testdata/pirate.feature | 8 ++ .../testdata/pirate.sample.en-pirate.feature | 8 ++ .../examples/simple.en-pirate.feature | 8 ++ .../simple/simple.en-pirate.feature_test.go | 21 +++ .../simple.en-pirate.feature_test.go | 21 +++ internal/generator/generator.go | 31 ++++- .../generator/generator_test.en-lol.feature | 8 ++ ...test.feature => generator_test.en.feature} | 2 +- internal/generator/generator_test.go | 107 ++++++++++++--- internal/generator/golang_test.go | 6 +- internal/generator/json_test.go | 2 +- internal/generator/raw_test.go | 4 +- scripts/examples.sh | 24 +++- 22 files changed, 521 insertions(+), 71 deletions(-) create mode 100644 internal/app/language.go create mode 100644 internal/app/testdata/english.feature create mode 100644 internal/app/testdata/english.sample.en.feature create mode 100644 internal/app/testdata/pirate.feature create mode 100644 internal/app/testdata/pirate.sample.en-pirate.feature create mode 100644 internal/generator/examples/simple.en-pirate.feature create mode 100644 internal/generator/examples/simple/simple.en-pirate.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/simple.en-pirate.feature_test.go create mode 100644 internal/generator/generator_test.en-lol.feature rename internal/generator/{generator_test.feature => generator_test.en.feature} (78%) diff --git a/.gitignore b/.gitignore index d7efa53..6d830cd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ bin # IDE .vscode +.idea # Test binary, built with `go test -c` *.test diff --git a/README.md b/README.md index a036297..671a2ce 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,13 @@ Usage of gherkingen [FEATURE_FILE]: add parallel mark (deprecated, enabled by default) (default true) -help print usage + -language string + Specifies the natural language used to describe the feature. + This flag is optional if language information is included in the feature file name, or if the feature is written in English. + The file name should be formatted as follows: ..feature if language hint is included, or .feature if it is not. + When provided, the 'language' flag takes precedence over the language hint from the file name. (default "en") + -languages + list supported natural feature languages -list list internal templates -package string @@ -251,7 +258,7 @@ create a pull request for supporting templates for them. For this: 3. Check: `make lint check.generate test`. 4. Commit&Push, create a PR. -## Language support +## Programming language support Templates are very customizable, so you can even generate non-golang code. In the command-line tool specify `raw` format using `-format` flag and your template using `-template` flag: `gherkingen -format raw -template example.tmpl example.feature`. diff --git a/internal/app/app.feature b/internal/app/app.feature index b9de0e8..94fc97f 100644 --- a/internal/app/app.feature +++ b/internal/app/app.feature @@ -1,55 +1,56 @@ Feature: Application command line tool + Scenario Outline: User wants to generate the output in given format When is given And is provided Then the output should be generated Examples: - | | | | - | app.feature | go | does | - | app.feature | json | does | - | app.feature | raw | does | - | app.feature | invalid | does not | - | notfound.feature | raw | does not | + | | | | + | app.feature | go | does | + | app.feature | json | does | + | app.feature | raw | does | + | app.feature | invalid | does not | + | notfound.feature | raw | does not | Scenario Outline: User wants to see usage information When is provided Then usage should be printed Examples: - | | - | --help | + | | + | --help | Scenario Outline: User wants to list built-in templates When is provided Then templates should be printed Examples: - | | - | --list | + | | + | --list | Scenario Outline: User wants to use custom template When