Skip to content

Commit 6452fe9

Browse files
committed
add more tests for pragma fix
1 parent ddaccc4 commit 6452fe9

15 files changed

+231
-3
lines changed

plugins/hls-pragmas-plugin/test/Main.hs

+36
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,42 @@ codeActionTests =
3232
liftIO $ "Add \"FlexibleInstances\"" `elem` map (^. L.title) cas @? "Contains FlexibleInstances code action"
3333
executeCodeAction $ head cas
3434

35+
, goldenWithPragmas "adds LANGUAGE pragma after shebang and last language pragma" "AfterShebangAndPragma" $ \doc -> do
36+
_ <- waitForDiagnosticsFrom doc
37+
cas <- map fromAction <$> getAllCodeActions doc
38+
liftIO $ "Add \"NamedFieldPuns\"" `elem` map (^. L.title) cas @? "Contains NamedFieldPuns code action"
39+
executeCodeAction $ head cas
40+
41+
, goldenWithPragmas "adds LANGUAGE pragma after GHC_OPTIONS" "AfterGhcOptions" $ \doc -> do
42+
_ <- waitForDiagnosticsFrom doc
43+
cas <- map fromAction <$> getAllCodeActions doc
44+
liftIO $ "Add \"TupleSections\"" `elem` map (^. L.title) cas @? "Contains TupleSections code action"
45+
executeCodeAction $ head cas
46+
47+
, goldenWithPragmas "adds LANGUAGE pragma after shebang and GHC_OPTIONS" "AfterShebangAndOpts" $ \doc -> do
48+
_ <- waitForDiagnosticsFrom doc
49+
cas <- map fromAction <$> getAllCodeActions doc
50+
liftIO $ "Add \"TupleSections\"" `elem` map (^. L.title) cas @? "Contains TupleSections code action"
51+
executeCodeAction $ head cas
52+
53+
, goldenWithPragmas "adds LANGUAGE pragma after shebang, GHC_OPTIONS and language pragma" "AfterShebangAndOptionsAndPragma" $ \doc -> do
54+
_ <- waitForDiagnosticsFrom doc
55+
cas <- map fromAction <$> getAllCodeActions doc
56+
liftIO $ "Add \"TupleSections\"" `elem` map (^. L.title) cas @? "Contains TupleSections code action"
57+
executeCodeAction $ head cas
58+
59+
, goldenWithPragmas "adds LANGUAGE pragma after all others ignoring later INLINE pragma" "AfterShebangAndOptionsAndPragmasIgnoreInline" $ \doc -> do
60+
_ <- waitForDiagnosticsFrom doc
61+
cas <- map fromAction <$> getAllCodeActions doc
62+
liftIO $ "Add \"TupleSections\"" `elem` map (^. L.title) cas @? "Contains TupleSections code action"
63+
executeCodeAction $ head cas
64+
65+
, goldenWithPragmas "adds LANGUAGE pragma after all others ignoring multiple later INLINE pragma" "AfterAllWithMultipleInlines" $ \doc -> do
66+
_ <- waitForDiagnosticsFrom doc
67+
cas <- map fromAction <$> getAllCodeActions doc
68+
liftIO $ "Add \"TupleSections\"" `elem` map (^. L.title) cas @? "Contains TupleSections code action"
69+
executeCodeAction $ head cas
70+
3571
, goldenWithPragmas "adds LANGUAGE pragma correctly ignoring later INLINE pragma" "AddLanguagePragma" $ \doc -> do
3672
_ <- waitForDiagnosticsFrom doc
3773
cas <- map fromAction <$> getAllCodeActions doc

plugins/hls-pragmas-plugin/test/testdata/AddLanguagePragma.expected renamed to plugins/hls-pragmas-plugin/test/testdata/AddLanguagePragma.expected.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{-# LANGUAGE OverloadedStrings #-}
1+
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE TupleSections #-}
33

4-
module NeedsLanguagePragms where
4+
module NeedsLanguagePragma where
55

66
tupleSection = (1,) <$> Just 2
77

plugins/hls-pragmas-plugin/test/testdata/AddLanguagePragma.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE OverloadedStrings #-}
22

3-
module NeedsLanguagePragms where
3+
module NeedsLanguagePragma where
44

55
tupleSection = (1,) <$> Just 2
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE RecordWildCards #-}
7+
{-# LANGUAGE TupleSections #-}
8+
9+
data Something = Something {
10+
foo :: !String,
11+
bar :: !Int
12+
}
13+
14+
tupleSection = (1, ) <$> Just 2
15+
16+
{-# INLINE addOne #-}
17+
addOne :: Int -> Int
18+
addOne x = x + 1
19+
20+
{-# INLINE subOne #-}
21+
subOne :: Int -> Int
22+
subOne x = x - 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE RecordWildCards #-}
7+
8+
data Something = Something {
9+
foo :: !String,
10+
bar :: !Int
11+
}
12+
13+
tupleSection = (1, ) <$> Just 2
14+
15+
{-# INLINE addOne #-}
16+
addOne :: Int -> Int
17+
addOne x = x + 1
18+
19+
{-# INLINE subOne #-}
20+
subOne :: Int -> Int
21+
subOne x = x - 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{-# OPTIONS_GHC -Wall #-}
2+
{-# OPTIONS_GHC -Wno-unused-imports #-}
3+
{-# LANGUAGE TupleSections #-}
4+
5+
data Something = Something {
6+
foo :: !String,
7+
bar :: !Int
8+
}
9+
10+
tupleSection = (1, ) <$> Just 2
11+
12+
{-# INLINE addOne #-}
13+
addOne :: Int -> Int
14+
addOne x = x + 1
15+
16+
{-# INLINE subOne #-}
17+
subOne :: Int -> Int
18+
subOne x = x - 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# OPTIONS_GHC -Wall #-}
2+
{-# OPTIONS_GHC -Wno-unused-imports #-}
3+
4+
data Something = Something {
5+
foo :: !String,
6+
bar :: !Int
7+
}
8+
9+
tupleSection = (1, ) <$> Just 2
10+
11+
{-# INLINE addOne #-}
12+
addOne :: Int -> Int
13+
addOne x = x + 1
14+
15+
{-# INLINE subOne #-}
16+
subOne :: Int -> Int
17+
subOne x = x - 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE TupleSections #-}
7+
8+
data Something = Something {
9+
foo :: !String,
10+
bar :: !Int
11+
}
12+
13+
tupleSection = (1, ) <$> Just 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
7+
data Something = Something {
8+
foo :: !String,
9+
bar :: !Int
10+
}
11+
12+
tupleSection = (1, ) <$> Just 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE RecordWildCards #-}
7+
{-# LANGUAGE TupleSections #-}
8+
9+
data Something = Something {
10+
foo :: !String,
11+
bar :: !Int
12+
}
13+
14+
tupleSection = (1, ) <$> Just 2
15+
16+
{-# INLINE addOne #-}
17+
addOne :: Int -> Int
18+
addOne x = x + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE RecordWildCards #-}
7+
8+
data Something = Something {
9+
foo :: !String,
10+
bar :: !Int
11+
}
12+
13+
tupleSection = (1, ) <$> Just 2
14+
15+
{-# INLINE addOne #-}
16+
addOne :: Int -> Int
17+
addOne x = x + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
{-# LANGUAGE TupleSections #-}
6+
7+
data Something = Something {
8+
foo :: !String,
9+
bar :: !Int
10+
}
11+
12+
tupleSection = (1, ) <$> Just 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# OPTIONS_GHC -Wall #-}
4+
{-# OPTIONS_GHC -Wno-unused-imports #-}
5+
6+
data Something = Something {
7+
foo :: !String,
8+
bar :: !Int
9+
}
10+
11+
tupleSection = (1, ) <$> Just 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE NamedFieldPuns #-}
5+
-- | Doc Comment
6+
{- Block -}
7+
8+
module BeforeDocComment where
9+
10+
data Record = Record
11+
{ a :: Int,
12+
b :: Double,
13+
c :: String
14+
}
15+
16+
f Record{a, b} = a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /usr/bin/env nix-shell
2+
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
3+
{-# LANGUAGE OverloadedStrings #-}
4+
-- | Doc Comment
5+
{- Block -}
6+
7+
module BeforeDocComment where
8+
9+
data Record = Record
10+
{ a :: Int,
11+
b :: Double,
12+
c :: String
13+
}
14+
15+
f Record{a, b} = a

0 commit comments

Comments
 (0)