<NME> RemovePipelineIntentionTest.kt
<BEF> package org.elm.ide.intentions



class RemovePipelineIntentionTest : ElmIntentionTestBase(RemovePipelineIntention()) {


    fun `test right pipe to no pipe`() = doAvailableTest(
module Foo exposing (list)

list =
    [1, 2, 3, 4] |> List.ma{-caret-}p times2

times2 m n = m * n
""", """
""", """
module Foo exposing (list)

list =
    List.map times2 [1, 2, 3, 4]

times2 m n = m * n
""")


    fun `test preserves comments`() = doAvailableTest(
            """
module Foo exposing (list)

list = 
    [1, 2, 3, 4] {- List.map 1 -}
        -- List.map 2
        {- List.map 3 -}
        |> List.ma{-caret-}p times2 -- identity 1
        -- identity 2
        |> identity -- end of line


times2 m n = m * n
""", """
module Foo exposing (list)

list = 
    -- top-level
    (-- identity 1
            -- identity 2
            identity
            ({- List.map 1 -}
        -- List.map 2
        {- List.map 3 -}
        List.map times2
        [1, 2, 3, 4]
        )
            ) -- end of line

times2 m n = m * n
""")

    fun `test remove pipeline example from elm-spa`() = doAvailableTest(
module Foo exposing (value)

value =
    Editor.i{-caret-}nitEdit session slug
        |> updateWith (Editor (Just slug)) GotEditorMsg model
""", """
module Foo exposing (value)


value =
    updateWith (Editor (Just slug)) GotEditorMsg model (Editor.initEdit session slug)
""")

    fun `test remove pipeline example 2 from elm-spa`() = doAvailableTest(
            """
module Foo exposing (value)
value msg =
    ( msg, True )
        |> Decode.succeed
        |> stop{-caret-}PropagationOn "click"
""", """
module Foo exposing (value)


value msg =
    stopPropagationOn "click" (Decode.succeed ( msg, True ))
""")

    fun `test remove pipeline example 3 from elm-spa`() = doAvailableTest(
            """
module Foo exposing (toggleFavoriteButton)
toggleFavoriteButton classStr msg attrs kids =
    i [ class "ion-heart" ] []
        :: kids
        |> Html.but{-caret-}ton (class classStr :: onClickStopPropagation msg :: attrs)
""", """
module Foo exposing (toggleFavoriteButton)


toggleFavoriteButton classStr msg attrs kids =
    Html.button (class classStr :: onClickStopPropagation msg :: attrs) (i [ class "ion-heart" ] [] :: kids)
""")

    fun `test remove left pipeline`() = doAvailableTest(
module Foo exposing (example)

example =
    flo{-caret-}or <| 1.3 + 4
""", """
module Foo exposing (example)


example =
    floor (1.3 + 4)
""")


    fun `test keeps parens around lambdas`() = doAvailableTest(
            """

example =
    (\fn -> fn [])
        |> List.m{-caret-}ap
""", """
module Foo exposing (example)


example =
    List.map (\fn -> fn [])
""")


    fun `test preserves indentation as starting point`() = doAvailableTest(
            """
module Foo exposing (src)

src : Avatar -> Attribute msg
src (Avatar maybeUrl) =
    case maybeUrl of
            identity
                (Asset.defaultAvatar
                    -- asdf
                    |> Asse{-caret-}t.src
                ) 

        Just "" ->
        Just "" ->
            Asset.src Asset.defaultAvatar

        Just url ->
            Html.Attributes.src url
""", """
module Foo exposing (src)

src : Avatar -> Attribute msg
src (Avatar maybeUrl) =
    case maybeUrl of
        Nothing ->
            identity
                ((-- asdf
                    Asset.src
                    Asset.defaultAvatar
                    )
                ) 

        Just "" ->
            Asset.src Asset.defaultAvatar

        Just url ->
            Html.Attributes.src url
""")

    fun `test paren is indented less than case statements to make valid whitespace`() = doAvailableTest(
            """
module Foo exposing (view)

view : Model -> { title : String, content : Html Msg }
view model =
    { title = "Conduit"
    , content =
        div
            [ "home-page"
                |> class
            ]
            [ viewBanner
            , div [ class "container page" ]
                [ div [ class "row" ]
                    [ div [ class "col-md-9" ] {-caret-}<|
                        case model.feed of
                            Loaded feed ->
                                [ div [ class "feed-toggle" ]
                                    (List.concat
                                        [ [ viewTabs
                                                (Session.cred model.session)
                                                model.feedTab
                                          ]
                                        , List.map (Html.map GotFeedMsg) (Feed.viewArticles model.timeZone feed)
                                        , [ Feed.viewPagination ClickedFeedPage model.feedPage feed ]
                                        ]
                                    )
                                ]

                            Loading ->
                                []

                            LoadingSlowly ->
                                [ Loading.icon ]

                            Failed ->
                                [ Loading.error "feed" ]
                    , div [ class "col-md-3" ] <|
                        case model.tags of
                            Loaded tags ->
                                [ div [ class "sidebar" ] <|
                                    [ p [] [ text "Popular Tags" ]
                                    , viewTags tags
                                    ]
                                ]

                            Loading ->
                                []

                            LoadingSlowly ->
                                [ Loading.icon ]

                            Failed ->
                                [ Loading.error "tags" ]
                    ]
                ]
            ]
    }
""", """
module Foo exposing (view)

view : Model -> { title : String, content : Html Msg }
view model =
    { title = "Conduit"
    , content =
        div
            [ "home-page"
                |> class
            ]
            [ viewBanner
            , div [ class "container page" ]
                [ div [ class "row" ]
                    [ div [ class "col-md-9" ]
                        case model.feed of
                            Loaded feed ->
                                [ div [ class "feed-toggle" ]
                                    (List.concat
                                        [ [ viewTabs
                                                (Session.cred model.session)
                                                model.feedTab
                                          ]
                                        , List.map (Html.map GotFeedMsg) (Feed.viewArticles model.timeZone feed)
                                        , [ Feed.viewPagination ClickedFeedPage model.feedPage feed ]
                                        ]
                                    )
                                ]

                            Loading ->
                                []

                            LoadingSlowly ->
                                [ Loading.icon ]

                            Failed ->
                                [ Loading.error "feed" ]
                    , div [ class "col-md-3" ] <|
                        case model.tags of
                            Loaded tags ->
                                [ div [ class "sidebar" ] <|
                                    [ p [] [ text "Popular Tags" ]
                                    , viewTags tags
                                    ]
                                ]

                            Loading ->
                                []

                            LoadingSlowly ->
                                [ Loading.icon ]

                            Failed ->
                                [ Loading.error "tags" ]
                    ]
                ]
            ]
    }
""")

    fun `test preserves comments with ordering`() = doAvailableTest(
            """
module Foo exposing (src)

src : Avatar -> Attribute msg
    case maybeUrl of
        Nothing ->
            -- user isn't logged in - use guest avatar
            Asset.defau{-caret-}ltAvatar
                -- normalizes trailing and leading /'s
                |> normalizeImageUrl
                -- sets the HTML src
                |> Asset.src



        Just "" ->
            Asset.src Asset.defaultAvatar

        Just url ->
            Html.Attributes.src url
""", """
module Foo exposing (src)

src : Avatar -> Attribute msg
src (Avatar maybeUrl) =
    case maybeUrl of
        Nothing ->
            -- user isn't logged in - use guest avatar
            (-- sets the HTML src
                    Asset.src
                    (-- normalizes trailing and leading /'s
                normalizeImageUrl
                Asset.defaultAvatar
                )
                    )


        Just "" ->
            Asset.src Asset.defaultAvatar

        Just url ->
            Html.Attributes.src url
""")

    fun `test multiline without comments`() = doAvailableTest(
            """

example =
    []
        |> List.m{-caret-}ap
            (identity
                identity
            )
            )
        |> List.map
            (identity
                identity
            )

""", """
module Foo exposing (example)

example =
    List.map
            (identity
                identity
            )
            (List.map
            (identity
                identity
            )
        []
        )

""")

    fun `test preserve comments right next to pipeline`() = doAvailableTest(
            """
module Foo exposing (example)
example =
    -- NotFound.view
    NotFound.view
        |> -- Page.view
           Page.v{-caret-}iew
            -- viewer
            viewer
            Page.Other
            Page.Other

""", """
module Foo exposing (example)

example =
    -- NotFound.view
    (-- Page.view
        Page.view
            -- viewer
            viewer
            Page.Other
        NotFound.view
        )

""")


    fun `test preserve comments right next to pipeline 2`() = doAvailableTest(
            """
module Foo exposing (example)
example =
    -- NotFound.view
    -- Page.view
    NotFound.vi{-caret-}ew
        -- viewer
        |> Page.view viewer Page.Other

""", """
module Foo exposing (example)
module Foo exposing (example)

example =
    -- NotFound.view
    -- Page.view
    (-- viewer
        Page.view viewer Page.Other
        NotFound.view
        )

""")
}

<MSG> Only show Remove Pipeline intention when the cursor is over a pipeline operator (#701)


<DFF> @@ -9,7 +9,7 @@ class RemovePipelineIntentionTest : ElmIntentionTestBase(RemovePipelineIntention
 module Foo exposing (list)
 
 list =
-    [1, 2, 3, 4] |> List.ma{-caret-}p times2
+    [1, 2, 3, 4] |{-caret-}> List.map times2
 
 times2 m n = m * n
 """, """
@@ -31,7 +31,7 @@ list =
     [1, 2, 3, 4] {- List.map 1 -}
         -- List.map 2
         {- List.map 3 -}
-        |> List.ma{-caret-}p times2 -- identity 1
+        {-caret-}|> List.map times2 -- identity 1
         -- identity 2
         |> identity -- end of line
 
@@ -60,8 +60,8 @@ times2 m n = m * n
 module Foo exposing (value)
 
 value =
-    Editor.i{-caret-}nitEdit session slug
-        |> updateWith (Editor (Just slug)) GotEditorMsg model
+    Editor.initEdit session slug
+        {-caret-}|> updateWith (Editor (Just slug)) GotEditorMsg model
 """, """
 module Foo exposing (value)
 
@@ -76,7 +76,7 @@ module Foo exposing (value)
 value msg =
     ( msg, True )
         |> Decode.succeed
-        |> stop{-caret-}PropagationOn "click"
+        {-caret-}|> stopPropagationOn "click"
 """, """
 module Foo exposing (value)
 
@@ -91,7 +91,7 @@ module Foo exposing (toggleFavoriteButton)
 toggleFavoriteButton classStr msg attrs kids =
     i [ class "ion-heart" ] []
         :: kids
-        |> Html.but{-caret-}ton (class classStr :: onClickStopPropagation msg :: attrs)
+        {-caret-}|> Html.button (class classStr :: onClickStopPropagation msg :: attrs)
 """, """
 module Foo exposing (toggleFavoriteButton)
 
@@ -104,7 +104,7 @@ toggleFavoriteButton classStr msg attrs kids =
 module Foo exposing (example)
 
 example =
-    flo{-caret-}or <| 1.3 + 4
+    floor {-caret-}<| 1.3 + 4
 """, """
 module Foo exposing (example)
 
@@ -119,7 +119,7 @@ module Foo exposing (example)
 
 example =
     (\fn -> fn [])
-        |> List.m{-caret-}ap
+        {-caret-}|> List.map
 """, """
 module Foo exposing (example)
 
@@ -139,7 +139,7 @@ src (Avatar maybeUrl) =
             identity
                 (Asset.defaultAvatar
                     -- asdf
-                    |> Asse{-caret-}t.src
+                    |>{-caret-} Asset.src
                 ) 
 
         Just "" ->
@@ -296,9 +296,9 @@ src (Avatar maybeUrl) =
     case maybeUrl of
         Nothing ->
             -- user isn't logged in - use guest avatar
-            Asset.defau{-caret-}ltAvatar
+            Asset.defaultAvatar
                 -- normalizes trailing and leading /'s
-                |> normalizeImageUrl
+                {-caret-}|> normalizeImageUrl
                 -- sets the HTML src
                 |> Asset.src
 
@@ -338,7 +338,7 @@ module Foo exposing (example)
 
 example =
     []
-        |> List.m{-caret-}ap
+        {-caret-}|> List.map
             (identity
                 identity
             )
@@ -371,8 +371,8 @@ module Foo exposing (example)
 example =
     -- NotFound.view
     NotFound.view
-        |> -- Page.view
-           Page.v{-caret-}iew
+        {-caret-}|> -- Page.view
+           Page.view
             -- viewer
             viewer
             Page.Other
@@ -400,9 +400,9 @@ module Foo exposing (example)
 example =
     -- NotFound.view
     -- Page.view
-    NotFound.vi{-caret-}ew
+    NotFound.view
         -- viewer
-        |> Page.view viewer Page.Other
+        {-caret-}|> Page.view viewer Page.Other
 
 """, """
 module Foo exposing (example)

Only show Remove Pipeline intention when the cursor is over a pipeline operator (#701)