Skip to content

Commit

Permalink
hls-notes-plugin: Fix tests on windows
Browse files Browse the repository at this point in the history
The regex did not allow windows line endings in note definitions
  • Loading branch information
jvanbruegge committed Feb 28, 2024
1 parent abcf822 commit e8e72d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ findNotesInFile file recorder = do
noteRefRegex, noteRegex :: Regex
(noteRefRegex, noteRegex) =
( mkReg ("note \\[(.+)\\]" :: String)
, mkReg ("note \\[([[:print:]]+)\\][[:blank:]]*[[:space:]][[:blank:]]*(--)?[[:blank:]]*~~~" :: String)
, mkReg ("note \\[([[:print:]]+)\\][[:blank:]]*\r?\n[[:blank:]]*(--)?[[:blank:]]*~~~" :: String)
)
where
mkReg = makeRegexOpts (defaultCompOpt { caseSensitive = False }) defaultExecOpt
11 changes: 6 additions & 5 deletions plugins/hls-notes-plugin/test/NotesTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Development.IDE.Test
import Ide.Plugin.Notes (Log, descriptor)
import System.Directory (canonicalizePath)
import System.FilePath ((</>))
import Test.Hls
import Test.Hls hiding (waitForBuildQueue)

plugin :: PluginTestDescriptor Log
plugin = mkPluginTestDescriptor descriptor "notes"
Expand All @@ -19,15 +19,15 @@ gotoNoteTests :: TestTree
gotoNoteTests = testGroup "Goto Note Definition"
[ testCase "single_file" $ runSessionWithServer def plugin testDataDir $ do
doc <- openDoc "NoteDef.hs" "haskell"
waitForCustomMessage "ghcide/cradle/loaded" (const $ Just ())
waitForBuildQueue
waitForAllProgressDone
defs <- getDefinitions doc (Position 3 41)
liftIO $ do
fp <- canonicalizePath "NoteDef.hs"
defs @?= InL (Definition (InR [Location (filePathToUri fp) (Range (Position 8 9) (Position 8 9))]))
, testCase "liberal_format" $ runSessionWithServer def plugin testDataDir $ do
doc <- openDoc "NoteDef.hs" "haskell"
waitForCustomMessage "ghcide/cradle/loaded" (const $ Just ())
waitForBuildQueue
waitForAllProgressDone
defs <- getDefinitions doc (Position 5 64)
liftIO $ do
Expand All @@ -36,22 +36,23 @@ gotoNoteTests = testGroup "Goto Note Definition"

, testCase "invalid_note" $ runSessionWithServer def plugin testDataDir $ do
doc <- openDoc "NoteDef.hs" "haskell"
waitForCustomMessage "ghcide/cradle/loaded" (const $ Just ())
waitForBuildQueue
waitForAllProgressDone
defs <- getDefinitions doc (Position 6 54)
liftIO $ do
defs @?= InL (Definition (InR []))

, testCase "no_note" $ runSessionWithServer def plugin testDataDir $ do
doc <- openDoc "NoteDef.hs" "haskell"
waitForCustomMessage "ghcide/cradle/loaded" (const $ Just ())
waitForBuildQueue
waitForAllProgressDone
defs <- getDefinitions doc (Position 1 0)
liftIO $ defs @?= InL (Definition (InR []))

, testCase "unopened_file" $ runSessionWithServer def plugin testDataDir $ do
doc <- openDoc "Other.hs" "haskell"
waitForCustomMessage "ghcide/cradle/loaded" (const $ Just ())
waitForBuildQueue
waitForAllProgressDone
defs <- getDefinitions doc (Position 5 20)
liftIO $ do
Expand Down

0 comments on commit e8e72d1

Please sign in to comment.