diff --git a/ansi/renderer_test.go b/ansi/renderer_test.go index 39bf289..39adcb8 100644 --- a/ansi/renderer_test.go +++ b/ansi/renderer_test.go @@ -16,8 +16,10 @@ import ( ) const ( - generate = false - examplesDir = "../styles/examples/" + generateExamples = false + generateIssues = false + examplesDir = "../styles/examples/" + issuesDir = "../testdata/issues/" ) func TestRenderer(t *testing.T) { @@ -70,7 +72,77 @@ func TestRenderer(t *testing.T) { } // generate - if generate { + if generateExamples { + err = ioutil.WriteFile(tn, buf.Bytes(), 0644) + if err != nil { + t.Fatal(err) + } + continue + } + + // verify + td, err := ioutil.ReadFile(tn) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(td, buf.Bytes()) { + t.Errorf("Rendered output for %s doesn't match!\nExpected: `\n%s`\nGot: `\n%s`\n", + bn, string(td), buf.String()) + } + } +} + +func TestRendererIssues(t *testing.T) { + files, err := filepath.Glob(issuesDir + "*.md") + if err != nil { + t.Fatal(err) + } + + for _, f := range files { + bn := strings.TrimSuffix(filepath.Base(f), ".md") + tn := filepath.Join(issuesDir, bn+".test") + + in, err := ioutil.ReadFile(f) + if err != nil { + t.Fatal(err) + } + b, err := ioutil.ReadFile("../styles/dark.json") + if err != nil { + t.Fatal(err) + } + + options := Options{ + WordWrap: 80, + } + err = json.Unmarshal(b, &options.Styles) + if err != nil { + t.Fatal(err) + } + + md := goldmark.New( + goldmark.WithExtensions( + extension.GFM, + extension.DefinitionList, + ), + goldmark.WithParserOptions( + parser.WithAutoHeadingID(), + ), + ) + + ar := NewRenderer(options) + md.SetRenderer( + renderer.NewRenderer( + renderer.WithNodeRenderers(util.Prioritized(ar, 1000)))) + + var buf bytes.Buffer + err = md.Convert(in, &buf) + if err != nil { + t.Error(err) + } + + // generate + if generateIssues { err = ioutil.WriteFile(tn, buf.Bytes(), 0644) if err != nil { t.Fatal(err) diff --git a/testdata/issues/42.md b/testdata/issues/42.md new file mode 100644 index 0000000..93624b3 --- /dev/null +++ b/testdata/issues/42.md @@ -0,0 +1,5 @@ +If you want to make a more significant change, please first [open an +issue](https://github.com/twpayne/chezmoi/issues/new) to discuss the change that +you want to make. Dave Cheney gives a [good +rationale](https://dave.cheney.net/2019/02/18/talk-then-code) as to why this is +important. diff --git a/testdata/issues/42.test b/testdata/issues/42.test new file mode 100644 index 0000000..58c5f24 --- /dev/null +++ b/testdata/issues/42.test @@ -0,0 +1,6 @@ + + If you want to make a more significant change, please first open an issue      + https://github.com/twpayne/chezmoi/issues/new to discuss the change that you   + want to make. Dave Cheney gives a good rationale                               + https://dave.cheney.net/2019/02/18/talk-then-code as to why this is important. + diff --git a/testdata/issues/43.md b/testdata/issues/43.md new file mode 100644 index 0000000..d2d2778 --- /dev/null +++ b/testdata/issues/43.md @@ -0,0 +1,7 @@ +* [Getting started](#getting-started) +* [Developing locally](#developing-locally) +* [Documentation changes](#documentation-changes) +* [Contributing changes](#contributing-changes) +* [Managing releases](#managing-releases) +* [Packaging](#packaging) +* [Updating the website](#updating-the-website) diff --git a/testdata/issues/43.test b/testdata/issues/43.test new file mode 100644 index 0000000..ddf4df5 --- /dev/null +++ b/testdata/issues/43.test @@ -0,0 +1,10 @@ + +                                                                                + • Getting started                                                              + • Developing locally                                                           + • Documentation changes                                                        + • Contributing changes                                                         + • Managing releases                                                            + • Packaging                                                                    + • Updating the website                                                         + diff --git a/testdata/issues/44.md b/testdata/issues/44.md new file mode 100644 index 0000000..6a735ce --- /dev/null +++ b/testdata/issues/44.md @@ -0,0 +1,6 @@ +| Distribution | Architectures | Package | +| ------------ | --------------------------------------------------------- | ------------------------------------------------------------------------- | +| Debian | `amd64`, `arm64`, `armel`, `i386`, `ppc64`, `ppc64le` | [`deb`](https://github.com/twpayne/chezmoi/releases/latest) | +| RedHat | `aarch64`, `armhfp`, `i686`, `ppc64`, `ppc64le`, `x86_64` | [`rpm`](https://github.com/twpayne/chezmoi/releases/latest) | +| OpenSUSE | `aarch64`, `armhfp`, `i686`, `ppc64`, `ppc64le`, `x86_64` | [`rpm`](https://github.com/twpayne/chezmoi/releases/latest) | +| Ubuntu | `amd64`, `arm64`, `armel`, `i386`, `ppc64`, `ppc64le` | [`deb`](https://github.com/twpayne/chezmoi/releases/latest) | diff --git a/testdata/issues/44.test b/testdata/issues/44.test new file mode 100644 index 0000000..fe04fb8 --- /dev/null +++ b/testdata/issues/44.test @@ -0,0 +1,13 @@ + +                                                                                +  DISTRIBUTION │ ARCHITECTURES │ PACKAGE                     + ───────────────┼────────────────────────────────┼──────────                    +  Debian │ amd64, arm64, armel, i386, │ deb                     +  │ ppc64, ppc64le │                     +  RedHat │ aarch64, armhfp, i686, ppc64, │ rpm                     +  │ ppc64le, x86_64 │                     +  OpenSUSE │ aarch64, armhfp, i686, ppc64, │ rpm                     +  │ ppc64le, x86_64 │                     +  Ubuntu │ amd64, arm64, armel, i386, │ deb                     +  │ ppc64, ppc64le │                     + diff --git a/testdata/issues/46_1.md b/testdata/issues/46_1.md new file mode 100644 index 0000000..90cdc19 --- /dev/null +++ b/testdata/issues/46_1.md @@ -0,0 +1,2 @@ +- Navigation + - Familiar shortcuts (arrows, ~, -, @), quick reference diff --git a/testdata/issues/46_1.test b/testdata/issues/46_1.test new file mode 100644 index 0000000..6ffe1d9 --- /dev/null +++ b/testdata/issues/46_1.test @@ -0,0 +1,6 @@ + +                                                                                + • Navigation                                                                   +   • Familiar shortcuts (arrows, ~, -, @), quick reference                      +                                                                                + diff --git a/testdata/issues/46_2.md b/testdata/issues/46_2.md new file mode 100644 index 0000000..e106414 --- /dev/null +++ b/testdata/issues/46_2.md @@ -0,0 +1,11 @@ +| Dependency | Installation | Operation | +| --- | --- | --- | +| xdg-open (Linux), open(1) (macOS), cygstart (Cygwin) | base | desktop opener | +| file, coreutils (cp, mv, rm), xargs | base | file type, copy, move and remove | +| tar, (un)zip [atool/bsdtar for more formats] | base | create, list, extract tar, gzip, bzip2, zip | +| archivemount, fusermount(3) | optional | mount, unmount archives | +| sshfs, [rclone](https://rclone.org/), fusermount(3) | optional | mount, unmount remotes | +| trash-cli | optional | trash files (default action: rm) | +| vlock (Linux), bashlock (macOS), lock(1) (BSD) | optional | terminal locker (fallback: [cmatrix](https://github.com/abishekvashok/cmatrix)) | +| advcpmv (Linux) ([integration](https://github.com/jarun/nnn/wiki/Advanced-use-cases#show-cp-mv-progress)) | optional | copy, move progress | +| `$VISUAL` (else `$EDITOR`), `$PAGER`, `$SHELL` | optional | fallback vi, less, sh | diff --git a/testdata/issues/46_2.test b/testdata/issues/46_2.test new file mode 100644 index 0000000..49e2e62 --- /dev/null +++ b/testdata/issues/46_2.test @@ -0,0 +1,20 @@ + +                                                                                +  DEPENDENCY │ INSTALLATION │ OPERATION          + ─────────────────────────────────┼──────────────┼───────────────────────────────── +  xdg-open (Linux), open(1) │ base │ desktop opener               +  (macOS), cygstart (Cygwin) │ │                              +  file, coreutils (cp, mv, rm), │ base │ file type, copy, move and    +  xargs │ │ remove                       +  tar, (un)zip [atool/bsdtar for │ base │ create, list, extract tar,   +  more formats] │ │ gzip, bzip2, zip             +  archivemount, fusermount(3) │ optional │ mount, unmount archives      +  sshfs, rclone, fusermount(3) │ optional │ mount, unmount remotes       +  trash-cli │ optional │ trash files (default action: +  │ │ rm)                          +  vlock (Linux), bashlock │ optional │ terminal locker (fallback:   +  (macOS), lock(1) (BSD) │ │ cmatrix)                     +  advcpmv (Linux) (integration) │ optional │ copy, move progress          +  $VISUAL (else $EDITOR), │ optional │ fallback vi, less, sh        +  $PAGER, $SHELL │ │                              + diff --git a/testdata/issues/47.md b/testdata/issues/47.md new file mode 100644 index 0000000..35e1634 --- /dev/null +++ b/testdata/issues/47.md @@ -0,0 +1 @@ +Example: `` diff --git a/testdata/issues/47.test b/testdata/issues/47.test new file mode 100644 index 0000000..461e1a8 --- /dev/null +++ b/testdata/issues/47.test @@ -0,0 +1,3 @@ + + Example:                                                       +