aboutsummaryrefslogtreecommitdiff
path: root/src/test/haskell
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/haskell')
-rw-r--r--src/test/haskell/Main.hs94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/test/haskell/Main.hs b/src/test/haskell/Main.hs
new file mode 100644
index 0000000..6581d0f
--- /dev/null
+++ b/src/test/haskell/Main.hs
@@ -0,0 +1,94 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import qualified Data.Text.IO as T
+import Test.Hspec
+
+import Model.Ad (Ad (..))
+import qualified Parser.LeboncoinParser as LeboncoinParser
+import qualified Parser.OuestFranceParser as OuestFranceParser
+
+main :: IO ()
+main = do
+ rawLeboncoinAds <- T.readFile "src/test/resources/leboncoin.html"
+ rawOuestFranceAds <- T.readFile "src/test/resources/ouestFrance.html"
+
+ hspec $ do
+ describe "LeboncoinParser" $ do
+
+ it "should parse no results from empty string" $ do
+ LeboncoinParser.parse "" `shouldBe` []
+
+ it "should parse ads from page" $ do
+ let ads =
+ [ Ad {name = "Chambre style hotel", location = "Dinan", price = Just "265\160\8364", url = "https://www.leboncoin.fr/locations/1450271298.htm?ca=6_s"}
+ , Ad {name = "Centre ville", location = "Brest", price = Just "420\160\8364", url = "https://www.leboncoin.fr/locations/1450271056.htm?ca=6_s"}
+ , Ad {name = "T3, Morlaix proche centre ville et port plaisance", location = "Morlaix", price = Just "395\160\8364", url = "https://www.leboncoin.fr/locations/1407544500.htm?ca=6_s"}
+ , Ad {name = "Appartement meuble", location = "Rennes", price = Just "565\160\8364", url = "https://www.leboncoin.fr/locations/1377975959.htm?ca=6_s"}
+ , Ad {name = "A louer T3", location = "La Chapelle-Janson", price = Just "420\160\8364", url = "https://www.leboncoin.fr/locations/1450270098.htm?ca=6_s"}
+ , Ad {name = "locations garage / garde meuble", location = "Landerneau", price = Just "50\160\8364", url = "https://www.leboncoin.fr/locations/1450174538.htm?ca=6_s"}
+ , Ad {name = "Studio meubl\233", location = "Lanester", price = Just "290\160\8364", url = "https://www.leboncoin.fr/locations/1450268170.htm?ca=6_s"}
+ , Ad {name = "Ergu\233-Gab\233ric - Maison - 3 chambres -", location = "Ergu\233-Gab\233ric", price = Just "655\160\8364", url = "https://www.leboncoin.fr/locations/1450267530.htm?ca=6_s"}
+ , Ad {name = "Studio meubl\233 \224 2 mn de la gare", location = "Rennes", price = Just "475\160\8364", url = "https://www.leboncoin.fr/locations/1450267333.htm?ca=6_s"}
+ , Ad {name = "Chambre \224 louer chez l,habitant", location = "Rennes", price = Just "450\160\8364", url = "https://www.leboncoin.fr/locations/1450266273.htm?ca=6_s"}
+ , Ad {name = "Appartement 3 pi\232ces 63 m\178", location = "Brest", price = Just "600\160\8364", url = "https://www.leboncoin.fr/locations/1426927284.htm?ca=6_s"}
+ , Ad {name = "recherche location", location = "Plaintel", price = Just "550\160\8364", url = "https://www.leboncoin.fr/locations/1450265866.htm?ca=6_s"}
+ , Ad {name = "Studio r\233nov\233 - Centre Ville Lorient", location = "Lorient", price = Just "360\160\8364", url = "https://www.leboncoin.fr/locations/1450265154.htm?ca=6_s"}
+ , Ad {name = "Centre historique, t2 meuble", location = "Vannes", price = Just "440\160\8364", url = "https://www.leboncoin.fr/locations/1450263864.htm?ca=6_s"}
+ , Ad {name = "appartement t3 parking priv\233", location = "Pontrieux", price = Just "390\160\8364", url = "https://www.leboncoin.fr/locations/1450251207.htm?ca=6_s"}
+ , Ad {name = "T1 Bis espace couchage ind\233pendant", location = "Brest", price = Just "360\160\8364", url = "https://www.leboncoin.fr/locations/1450263863.htm?ca=6_s"}
+ , Ad {name = "Grand T2 boulevard Gambetta", location = "Brest", price = Just "400\160\8364", url = "https://www.leboncoin.fr/locations/1450263306.htm?ca=6_s"}
+ , Ad {name = "chambre meubl\233e", location = "Bourg-des-Comptes", price = Just "300\160\8364", url = "https://www.leboncoin.fr/locations/1450246530.htm?ca=6_s"}
+ , Ad {name = "Un studio de charme au centre de Landerneau", location = "Landerneau", price = Just "310\160\8364", url = "https://www.leboncoin.fr/locations/1433376198.htm?ca=6_s"}
+ , Ad {name = "Appartement T2 plein centre.", location = "Plum\233liau", price = Just "385\160\8364", url = "https://www.leboncoin.fr/locations/1450262744.htm?ca=6_s"}
+ , Ad {name = "Recherche l'appartement parfait", location = "Rennes", price = Just "360\160\8364", url = "https://www.leboncoin.fr/locations/1450260894.htm?ca=6_s"}
+ , Ad {name = "Location appartement meuble", location = "Saint-Malo", price = Just "510\160\8364", url = "https://www.leboncoin.fr/locations/1421964890.htm?ca=6_s"}
+ , Ad {name = "Maison neuve Lambezelec", location = "Plabennec", price = Just "900\160\8364", url = "https://www.leboncoin.fr/locations/1450259912.htm?ca=6_s"}
+ , Ad {name = "Chambre kitchenette chez l'habitant", location = "Brest", price = Just "320\160\8364", url = "https://www.leboncoin.fr/locations/1450258838.htm?ca=6_s"}
+ , Ad {name = "Studio 20m2 Rennes Ouest", location = "Rennes", price = Just "395\160\8364", url = "https://www.leboncoin.fr/locations/1450258223.htm?ca=6_s"}
+ , Ad {name = "Maison Ploufragan", location = "Ploufragan", price = Just "680\160\8364", url = "https://www.leboncoin.fr/locations/1450257866.htm?ca=6_s"}
+ , Ad {name = "Studio centre villes Rennes", location = "Rennes", price = Just "425\160\8364", url = "https://www.leboncoin.fr/locations/1450257277.htm?ca=6_s"}
+ , Ad {name = "Grand T2 Saint-Brieuc proche Renan", location = "Saint-Brieuc", price = Just "375\160\8364", url = "https://www.leboncoin.fr/locations/1450257042.htm?ca=6_s"}
+ , Ad {name = "Location maison T3", location = "Langueux", price = Just "569\160\8364", url = "https://www.leboncoin.fr/locations/1439054110.htm?ca=6_s"}
+ , Ad {name = "Chambre", location = "Vannes", price = Just "150\160\8364", url = "https://www.leboncoin.fr/locations/1450255229.htm?ca=6_s"}
+ , Ad {name = "Appartement meubl\233 2 ch centre Brest", location = "Brest", price = Just "750\160\8364", url = "https://www.leboncoin.fr/locations/1450255216.htm?ca=6_s"}
+ , Ad {name = "Brest Base Navale/porte Caffa - possible meubl\233", location = "Brest", price = Just "390\160\8364", url = "https://www.leboncoin.fr/locations/1433862279.htm?ca=6_s"}
+ , Ad {name = "Appartement Rennes", location = "Rennes", price = Just "390\160\8364", url = "https://www.leboncoin.fr/locations/1450254830.htm?ca=6_s"}
+ , Ad {name = "Location Appartement Villejean", location = "Rennes", price = Just "400\160\8364", url = "https://www.leboncoin.fr/locations/1450253542.htm?ca=6_s"}
+ , Ad {name = "Maison de bourg 3 chambres B\233d\233e", location = "B\233d\233e", price = Just "570\160\8364", url = "https://www.leboncoin.fr/locations/1450252631.htm?ca=6_s"}
+ ]
+
+ LeboncoinParser.parse rawLeboncoinAds `shouldBe` ads
+
+ describe "OuestFranceParser" $ do
+
+ it "should parse no results from empty string" $ do
+ OuestFranceParser.parse "" `shouldBe` []
+
+ it "should parse ads from page" $ do
+ let ads =
+ [ Ad {name = "Maison 3 chambres", location = "Rennes", price = Just "210\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13108048.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Sacr\233 Coeurs", price = Just "1 094\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13114249.htm"}
+ , Ad {name = "Maison 1 pi\232ce", location = "Rennes Bourg L'ev\234que", price = Just "370\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13113524.htm"}
+ , Ad {name = "Maison 2 chambres", location = "Rennes Sainte-Th\233r\232se", price = Just "869\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13111302.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Nord Saint-Martin", price = Just "1 650\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13109610.htm"}
+ , Ad {name = "Maison 2 chambres", location = "Rennes Sainte-Th\233r\232se", price = Just "915\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13020322.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Brequigny", price = Just "1 011\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13107308.htm"}
+ , Ad {name = "Maison 6 chambres", location = "Rennes Jeanne D'arc", price = Just "2 715\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13104531.htm"}
+ , Ad {name = "Maison 3 chambres", location = "Rennes", price = Just "1 025\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13104556.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Patton", price = Just "1 270\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12742357.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Jeanne D'arc", price = Just "1 616\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12938970.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Sainte-Th\233r\232se", price = Just "1 910\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/13050770.htm"}
+ , Ad {name = "Maison 7 chambres", location = "Rennes Centre Ville", price = Just "3 000\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12888774.htm"}
+ , Ad {name = "Maison 5 chambres", location = "Rennes Patton", price = Just "1 500\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12317304.htm"}
+ , Ad {name = "Maison 6 chambres", location = "Rennes Sainte-Th\233r\232se", price = Just "1 850\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12874271.htm"}
+ , Ad {name = "Maison 4 chambres", location = "Rennes Sud", price = Just "895\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/11139843.htm"}
+ , Ad {name = "Maison 3 chambres", location = "Rennes Cleunay", price = Just "760\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/11538097.htm"}
+ , Ad {name = "Maison 5 chambres", location = "Rennes Sud", price = Just "725\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/11538087.htm"}
+ , Ad {name = "Maison 2 pi\232ces", location = "Rennes Sacr\233 Coeurs", price = Just "420\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12892421.htm"}
+ , Ad {name = "Maison 2 chambres", location = "Rennes Centre Ville", price = Just "700\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/11918621.htm"}
+ , Ad {name = "Maison 5 pi\232ces", location = "Rennes Arsenal - Redon", price = Just "760\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/11139832.htm"}
+ , Ad {name = "Maison 2 chambres", location = "Rennes Centre Ville", price = Just "900\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12247109.htm"}
+ , Ad {name = "Maison 4 pi\232ces", location = "Rennes Nord Saint-Martin", price = Just "680\160\8364", url = "https://www.ouestfrance-immo.com//immobilier/location/maison/rennes-35-35238/12973592.htm"}
+ ]
+
+ OuestFranceParser.parse rawOuestFranceAds `shouldBe` ads