<commit_before>{-# LANGUAGE OverloadedStrings #-}

import System.Exit

import Text.Trifecta

import Parser
import AST

doTest (input, result) = case parseOnly pFile input of
   Success p | p == result -> putStrLn ("pass: " ++ show input ++ " parsed to " ++ show p) >> return True
             | otherwise   -> putStrLn ("fail: " ++ show input ++ " did not parse to " ++ show result ++ " but " ++ show p) >> return False
   Failure e -> putStrLn ("fail: " ++ show input ++ " failed to parse:\n" ++ show e) >> return False

doTests = mapM doTest

tests =
  [ ("s/a/b/g", [Sed Always (Subst (Just (RE "a")) "b" [SubstGlobal])])
  , ("s/\\//\\//", [Sed Always (Subst (Just (RE "/")) "/" [])])
  , ("s|\\||\\||", [Sed Always (Subst (Just (RE "|")) "|" [])])
  , ("s///", [Sed Always (Subst Nothing "" [])])
  , ("s/\\.//", [Sed Always (Subst (Just (RE "\\.")) "" [])])
  , ("/\\./ s///", [Sed (At (Match (Just (RE "\\.")))) (Subst Nothing "" [])])

  , ("// s///", [Sed (At (Match Nothing)) (Subst Nothing "" [])])
  , ("\\// s///", [Sed (At (Match Nothing)) (Subst Nothing "" [])])
  , ("\\|| s|||", [Sed (At (Match Nothing)) (Subst Nothing "" [])])
  , ("\\/\\//s///", [Sed (At (Match (Just (RE "/")))) (Subst Nothing "" [])])
  , ("\\|\\|| s|||", [Sed (At (Match (Just (RE "|")))) (Subst Nothing "" [])])
  ]

counts [] = (0,0)
counts (x:xs) | x = (trues + 1, falses)
              | otherwise = (trues, falses + 1)
              where (trues, falses) = counts xs

main = do
    results <- doTests tests
    let (passes, fails) = counts results
    case fails of
      0 -> exitSuccess
      -- putStrLn ("Finished " ++ show (length tests) ++ " tests")
      _ -> putStrLn (show fails ++ " tests failed") >> exitFailure<commit_msg>Make successful parser tests less verbose<commit_after>{-# LANGUAGE OverloadedStrings #-}

import System.Exit

import Text.Trifecta

import Parser
import AST

doTest (input, result) = case parseOnly pFile input of
   Success p | p == result -> return True -- putStrLn ("pass: " ++ show input ++ " parsed to " ++ show p) >> return True
             | otherwise   -> putStrLn ("fail: " ++ show input ++ " did not parse to " ++ show result ++ " but " ++ show p) >> return False
   Failure e -> putStrLn ("fail: " ++ show input ++ " failed to parse:\n" ++ show e) >> return False

doTests = mapM doTest

tests =
  [ ("s/a/b/g", [Sed Always (Subst (Just (RE "a")) "b" [SubstGlobal])])
  , ("s/\\//\\//", [Sed Always (Subst (Just (RE "/")) "/" [])])
  , ("s|\\||\\||", [Sed Always (Subst (Just (RE "|")) "|" [])])
  , ("s///", [Sed Always (Subst Nothing "" [])])
  , ("s/\\.//", [Sed Always (Subst (Just (RE "\\.")) "" [])])
  , ("/\\./ s///", [Sed (At (Match (Just (RE "\\.")))) (Subst Nothing "" [])])

  , ("// s///", [Sed (At (Match Nothing)) (Subst Nothing "" [])])
  , ("\\// s///", [Sed (At (Match Nothing)) (Subst Nothing "" [])])
  , ("\\|| s|||", [Sed (At (Match Nothing)) (Subst Nothing "" [])])
  , ("\\/\\//s///", [Sed (At (Match (Just (RE "/")))) (Subst Nothing "" [])])
  , ("\\|\\|| s|||", [Sed (At (Match (Just (RE "|")))) (Subst Nothing "" [])])
  ]

counts [] = (0,0)
counts (x:xs) | x = (trues + 1, falses)
              | otherwise = (trues, falses + 1)
              where (trues, falses) = counts xs

main = do
    results <- doTests tests
    let (passes, fails) = counts results
    case fails of
      0 -> putStrLn "OK" >> exitSuccess
      -- putStrLn ("Finished " ++ show (length tests) ++ " tests")
      _ -> putStrLn (show fails ++ " tests failed") >> exitFailure
{'fraction_non_alphanumeric': 0.25639567936327456, 'fraction_numerical': 0.0028425241614553724, 'mean_word_length': 2.605532786885246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, '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': '3337997', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1282, 'n_words': 382}