Skip to content

Commit

Permalink
test: add another rst case
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed May 18, 2024
1 parent 1a7fe6d commit 26ece6e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/lint/rst.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import (
// `::` for rst2html, including the use of runtime options (e.g., :caption:).
var reCodeBlock = regexp.MustCompile(`.. (?:raw|code(?:-block)?):: (?:[\w-]+)(?:\s+:\w+: .+)*`)

// HACK: We replace custom Sphinx directives with `.. code::`.
//
// This isn't ideal, but it appears to be necessary.
// We replace custom directives with `.. code::`.
//
// See https://github.com/errata-ai/vale/v2/issues/119.
var reSphinx = regexp.MustCompile(`.. glossary::`)
var reSphinx = regexp.MustCompile(`.. (?:glossary|contents)::`)
var rstArgs = []string{
"--quiet",
"--halt=5",
Expand Down
11 changes: 11 additions & 0 deletions testdata/features/lint.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ Feature: Lint
test.org:50:18:vale.Annotations:'TODO' left in text
"""

Scenario: Lint a reStructuredText file
When I lint A "test.rst"
Then the output should contain exactly:
"""
test.rst:15:1:Test.Test3:Use 'BIG Needles' rather than 'BIG needles'.
test.rst:22:59:Test.Test3:Use 'BIG Needles' rather than 'BIG needles'.
test.rst:23:43:Test.Test3:Use 'BIG Needles' rather than 'BIG needles'.
test.rst:25:22:Test.Test3:Use 'BIG Needles' rather than 'BIG needles'.
test.rst:29:17:Test.Test3:Use 'BIG Needles' rather than 'BIG needles'.
"""

Scenario: Lint a AsciiDoc file
When I lint AsciiDoc "test.adoc"
Then the output should contain exactly:
Expand Down
5 changes: 5 additions & 0 deletions testdata/features/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
step %(I run `#{cmd} #{file}`)
end

When(/^I lint reStructuredText "(.*)"$/) do |file|
step %(I cd to "../../fixtures/formats/rst")
step %(I run `#{cmd} #{file}`)
end

When(/^I lint file "([^\s]+)" as "([^\s]+)"$/) do |file, ext|
step %(I cd to "../../fixtures/formats")
step %(I run `#{cmd} --ext='#{ext}' #{file}`)
Expand Down
4 changes: 4 additions & 0 deletions testdata/fixtures/formats/rst/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
StylesPath = styles

[test.rst]
Test.Rule = YES
9 changes: 9 additions & 0 deletions testdata/fixtures/formats/rst/styles/Test/Rule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
extends: substitution
ignorecase: false
level: error
message: "Use '%s' rather than '%s'."
action:
name: replace
swap:
BIG needles: BIG Needles
29 changes: 29 additions & 0 deletions testdata/fixtures/formats/rst/test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
###############
Picking Needles
###############

.. contents::
:depth: 2
:local:
:backlinks: none


*****************
About BIG Needles
*****************

BIG needles with lowercase n is not matched under the following conditions:

* I use a B in BIG.
* I use the preceding contents directive.

However...

* Changing the preceding heading to PIG Needles, and then BIG needles is matched.
* Remove the contents directive, and then BIG needles is matched.

But, in other places BIG needles is matched.

.. note::

Other times, BIG needles is found.

0 comments on commit 26ece6e

Please sign in to comment.