<commit_before>module Main (main) where

import ClassyPrelude
import Data.Either (isRight, isLeft)
import Test.Hspec
import Test.QuickCheck (property, Arbitrary(..), oneof)
import qualified Data.Text as T

import NixFromNpm

main :: IO ()
main = hspec $ do
  describe "tests" $ do
    it "should work" $ do
      True `shouldBe` True<commit_msg>start building unit tests for npm version ranges<commit_after>module Unit (main) where

import ClassyPrelude
import Data.Either (isRight, isLeft)
import Test.Hspec
import Test.QuickCheck (property, Arbitrary(..), oneof)
import qualified Data.Text as T

import NixFromNpm
import NixFromNpm.Git.Types (GitRef(..), refText)
import NixFromNpm.Npm.Version.Parser

shouldBeR :: (Eq a, Eq b, Show a, Show b) => Either a b -> b -> Expectation
shouldBeR a b = a `shouldBe` Right b

npmVersionParserSpec :: Spec
npmVersionParserSpec = describe "npm version parser" $ do
  describe "semvers" $ do
    it "should parse a semver" $ do
      parseNpmVersionRange "0.0.0" `shouldBeR` SemVerRange (Eq (semver 0 0 0))

    it "should parse a tag" $ do
      parseNpmVersionRange "xyz" `shouldBeR` Tag "xyz"

    it "should parse a github uri" $ do
      let owner = "holidaycheck"
          repo = "reactautosuggest"
          ref = CommitHash "43074a439d26243ea07110f0c5752a6fc8aebe4d"
      let uri = joinBy "/" ["https://github.com", owner, repo, refText ref]
      parseNpmVersionRange uri `shouldBeR` GitId Github owner repo (Just ref)

main :: IO ()
main = hspec $ do
  npmVersionParserSpec
{'fraction_non_alphanumeric': 0.0984251968503937, 'fraction_numerical': 0.02099737532808399, 'mean_word_length': 3.8722044728434506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3895001', 'n_tokens_mistral': 533, 'n_tokens_neox': 500, 'n_words': 171}