2017-03-08 21:33:55 +03:00
|
|
|
-- Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- This source code is licensed under the BSD-style license found in the
|
2019-05-22 20:36:43 +03:00
|
|
|
-- LICENSE file in the root directory of this source tree.
|
2017-03-08 21:33:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Duckling.Engine.Tests
|
|
|
|
( tests
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.String
|
|
|
|
import Prelude
|
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit
|
|
|
|
|
|
|
|
import Duckling.Engine
|
|
|
|
import Duckling.Types
|
2017-04-15 01:34:29 +03:00
|
|
|
import Duckling.Dimensions.Types
|
|
|
|
import Duckling.Regex.Types
|
2017-03-08 21:33:55 +03:00
|
|
|
|
|
|
|
tests :: TestTree
|
|
|
|
tests = testGroup "Engine Tests"
|
|
|
|
[ emptyRegexTest
|
2017-04-15 01:34:29 +03:00
|
|
|
, unicodeAndRegexTest
|
2017-03-08 21:33:55 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
emptyRegexTest :: TestTree
|
|
|
|
emptyRegexTest = testCase "Empty Regex Test" $
|
|
|
|
case regex "()" of
|
2017-04-01 00:05:57 +03:00
|
|
|
Regex regex -> assertEqual "empty result" [] $
|
2017-04-28 18:58:31 +03:00
|
|
|
runDuckling $ lookupRegexAnywhere "hey" regex
|
2017-03-08 21:33:55 +03:00
|
|
|
_ -> assertFailure "expected a regex"
|
2017-04-15 01:34:29 +03:00
|
|
|
|
|
|
|
unicodeAndRegexTest :: TestTree
|
|
|
|
unicodeAndRegexTest = testCase "Unicode and Regex Test" $
|
|
|
|
case regex "\\$([0-9]*)" of
|
|
|
|
Regex regex -> do --
|
|
|
|
assertEqual "" expected $
|
2017-04-28 18:58:31 +03:00
|
|
|
runDuckling $ lookupRegexAnywhere "\128526 $35" regex
|
2017-04-15 01:34:29 +03:00
|
|
|
_ -> assertFailure "expected a regex"
|
|
|
|
where
|
|
|
|
expected =
|
|
|
|
[ Node
|
|
|
|
{ nodeRange = Range 2 5
|
|
|
|
, token = Token RegexMatch (GroupMatch ["35"])
|
|
|
|
, children = []
|
|
|
|
, rule = Nothing
|
|
|
|
}
|
|
|
|
]
|