-
-
Notifications
You must be signed in to change notification settings - Fork 13
Look for test name to task id mapping in manifest #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fredefox
wants to merge
2
commits into
exercism:main
Choose a base branch
from
fredefox:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ results.json | |
stack.yaml.lock | ||
bin/setup-tests | ||
tests/**/HspecFormatter.hs | ||
**/dist-newstyle/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module LeapYear (isLeapYear) where | ||
|
||
isLeapYear :: Integer -> Bool | ||
isLeapYear year = error "You need to implement this function." | ||
isLeapYear _year = error "You need to implement this function." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# language OverloadedStrings #-} | ||
{-# language LambdaCase #-} | ||
module Manifest ( Manifest, getTaskId, getManifest ) where | ||
|
||
import Data.Aeson ( FromJSON (parseJSON), (.:)) | ||
import qualified Data.Aeson as Aeson | ||
import Data.Map (Map) | ||
import qualified Data.Map as Map | ||
import Data.Text (Text) | ||
import qualified Data.Text as Text | ||
import System.Directory | ||
import System.FilePath ((</>)) | ||
import Text.Printf (printf) | ||
import Data.Bifunctor (first) | ||
|
||
newtype Test = Test | ||
{ taskId :: Maybe Int | ||
} | ||
|
||
instance FromJSON Test where | ||
parseJSON = Aeson.withObject "test" $ \v -> Test <$> v .: "task_id" | ||
|
||
newtype Manifest = Manifest | ||
{ _tests :: Map Text Test | ||
} | ||
|
||
instance FromJSON Manifest where | ||
parseJSON = Aeson.withObject "manifest" $ \v -> Manifest <$> v .: "tests" | ||
|
||
-- | Map test description to task ID based on a manifest. | ||
getTaskId :: Manifest -> String -> Maybe Int | ||
getTaskId (Manifest m) name = Map.lookup (Text.pack name) m >>= taskId | ||
|
||
findManifest :: IO (Either String FilePath) | ||
findManifest = do | ||
d <- getCurrentDirectory | ||
let p = d </> ".exercism/metadata.json" | ||
doesFileExist p >>= \case | ||
False -> pure $ Left $ printf "Could not find manifest: %s" p | ||
True -> pure $ Right p | ||
|
||
getManifest :: IO (Either String Manifest) | ||
getManifest = findManifest >>= \case | ||
Right p -> first (printf "Could not decode manifest: %s") <$> Aeson.eitherDecodeFileStrict p | ||
Left e -> pure $ Left e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"tests": { | ||
"2015 - year not divisible by 4 in common year": { "task_id": 1 }, | ||
"1970 - year divisible by 2, not divisible by 4 in common year": { "task_id": 1 }, | ||
"1996 - year divisible by 4, not divisible by 100 in leap year": { "task_id": 1 }, | ||
"1960 - year divisible by 4 and 5 is still a leap year": { "task_id": 1 }, | ||
"2100 - year divisible by 100, not divisible by 400 in common year": { "task_id": 1 }, | ||
"1900 - year divisible by 100 but not by 3 is still not a leap year": { "task_id": 1 }, | ||
"2000 - year divisible by 400 in leap year": { "task_id": 1 }, | ||
"2400 - year divisible by 400 but not by 125 is still a leap year": { "task_id": 1 }, | ||
"1800 - year divisible by 200, not divisible by 400 in common year": { "task_id": 1 } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big Haskeller, but I've never seen this being used in Haskell code (I know the operator from F#, Elm and Elixir). @MatthijsBlom, your thoughts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hoogle:
|>
. As expected, I spot a fewflip ($)
synonyms and a lot of cons-likes, but no(,)
synonyms. I have never previously seen this use of|>
(and such) in Haskell.This definition reminds me of Julia's
=>
.