1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Merge branch 'master' into normalize-unevaluated-module-tables

This commit is contained in:
Josh Vera 2018-06-05 13:04:30 -04:00 committed by GitHub
commit dd3fe37269
3 changed files with 44 additions and 1 deletions

View File

@ -281,6 +281,7 @@ test-suite test
, Diffing.Interpreter.Spec
, Integration.Spec
, Matching.Go.Spec
, Proto3.Roundtrip
, Rendering.TOC.Spec
, Semantic.Spec
, Semantic.CLI.Spec
@ -295,6 +296,7 @@ test-suite test
, bifunctors
, bytestring
, comonad
, containers
, effects
, fastsum
, filepath
@ -309,7 +311,8 @@ test-suite test
, leancheck
, mtl
, network
, containers
, proto3-suite
, proto3-wire
, recursion-schemes >= 4.1
, semantic
, text >= 1.2.1.3

38
test/Proto3/Roundtrip.hs Normal file
View File

@ -0,0 +1,38 @@
{-# LANGUAGE TypeApplications #-}
module Proto3.Roundtrip (spec) where
import SpecHelpers
import Data.Span
import qualified Data.ByteString.Lazy as L
import Data.Source
import Proto3.Suite
import qualified Proto3.Wire.Encode as E
shouldRoundtrip :: (Eq a, Show a, Message a) => a -> Expectation
shouldRoundtrip a = go a `shouldBe` Right a
where go = fromByteString . L.toStrict . toLazyByteString
spec :: Spec
spec = parallel $ do
describe "spans" $
prop "roundtrips" $
\sp -> shouldRoundtrip @Span sp
describe "blobs" $ do
it "should roundtrip given a Message instance" $ do
let bl = Blob (fromUTF8 "puts 'hi'") "example.rb" Ruby
shouldRoundtrip bl
describe "languages" $ do
-- If this test broke, it means you've probably added another 'Language'.
-- Add it to the list of languages below and everything should be good,
-- as long as you added it in a way that doesn't break prior Enum encodings.
it "should match up with Enum declarations" $ do
let go :: (Primitive f, MessageField f) => [f] -> [L.ByteString]
go x = E.toLazyByteString . encodePrimitive (fieldNumber 0) <$> x
let ints = [0..fromEnum (maxBound @Language)]
let langs = [Unknown, Go, Haskell, Java, JavaScript, JSON,
JSX, Markdown, Python, Ruby, TypeScript, PHP]
go ints `shouldBe` go langs

View File

@ -23,6 +23,7 @@ import qualified Semantic.Spec
import qualified Semantic.CLI.Spec
import qualified Semantic.IO.Spec
import qualified Semantic.Stat.Spec
import qualified Proto3.Roundtrip
import Test.Hspec
main :: IO ()
@ -51,3 +52,4 @@ main = hspec $ do
describe "Semantic.CLI" Semantic.CLI.Spec.spec
describe "Semantic.IO" Semantic.IO.Spec.spec
describe "Integration" Integration.Spec.spec
describe "Protobuf roundtripping" Proto3.Roundtrip.spec