Skip to content

Commit

Permalink
first working executable
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjoosten committed May 21, 2020
1 parent d9dc639 commit 9b627b0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changelog for encodingTest
# Changelog for utf8Guard

## Unreleased changes
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# encodingTest
# utf8Guard

## Execute
Ever had a file that should contain only valid utf8 characters, but for some reason invalid unicode codepoints are in?
This little tool comes to the rescue. It substitues all those invalid stuff with a valid dummy character.

* Run `stack exec -- encodingTest-exe` to see "We're inside the application!"
* With `stack exec -- encodingTest-exe --verbose` you will see the same message, with more logging.

## Run tests

`stack test`
4 changes: 2 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Import
import Run
import RIO.Process
import Options.Applicative.Simple
import qualified Paths_encodingTest
import qualified Paths_utf8Guard

main :: IO ()
main = do
(options, ()) <- simpleOptions
$(simpleVersion Paths_encodingTest.version)
$(simpleVersion Paths_utf8Guard.version)
"Header for command line arguments"
"Program description, also for command line arguments"
(Options
Expand Down
18 changes: 9 additions & 9 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: encodingTest
name: utf8Guard
version: 0.1.0.0
github: hanjoosten/encodingTest
github: hanjoosten/utf8Guard
license: BSD3
author: Han Joosten
maintainer: [email protected]
Expand All @@ -11,13 +11,13 @@ extra-source-files:
- ChangeLog.md

# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
synopsis: Substitute invalid utf8 characters with a valid one.
category: tools

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on Github at <https://github.com/hanjoosten/encodingTest#readme>
description: Please see the README on Github at <https://github.com/hanjoosten/utf8Guard#readme>

dependencies:
- base >= 4.11 && < 10
Expand All @@ -36,11 +36,11 @@ library:
source-dirs: src

executables:
encodingTest-exe:
utf8Guard:
main: Main.hs
source-dirs: app
dependencies:
- encodingTest
- utf8Guard
- optparse-simple

ghc-options:
Expand All @@ -49,11 +49,11 @@ executables:
- -with-rtsopts=-N

tests:
encodingTest-test:
utf8Guard-test:
main: Spec.hs
source-dirs: test
dependencies:
- encodingTest
- utf8Guard
- hspec

ghc-options:
Expand Down
9 changes: 8 additions & 1 deletion src/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
module Run (run) where

import Import
import qualified RIO.ByteString.Lazy as BL

run :: RIO App ()
run = do
logInfo "We're inside the application!"
bs <- BL.hGetContents stdin
let bsSafe = doProces bs
BL.hPut stdout bsSafe

doProces :: BL.ByteString -> BL.ByteString
doProces = BL.fromStrict . encodeUtf8 . decodeUtf8With lenientDecode . BL.toStrict

12 changes: 12 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 496112
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/13.yaml
sha256: 75a1a0f870e1876898b117b0e443f911b3fa2985bfabb53158c81ab5765beda5
original: lts-15.13
26 changes: 13 additions & 13 deletions encodingTest.cabal → utf8Guard.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: e254cc937334827eb1c9e6f050d5ebff4392c688fc48e98d4ba939e3b262fd5f
-- hash: 35ea6b80b972fc51d885abf9878fb59856c5d6f116764b70244c92ab2c376819

name: encodingTest
name: utf8Guard
version: 0.1.0.0
description: Please see the README on Github at <https://github.com/hanjoosten/encodingTest#readme>
homepage: https://github.com/hanjoosten/encodingTest#readme
bug-reports: https://github.com/hanjoosten/encodingTest/issues
description: Please see the README on Github at <https://github.com/hanjoosten/utf8Guard#readme>
homepage: https://github.com/hanjoosten/utf8Guard#readme
bug-reports: https://github.com/hanjoosten/utf8Guard/issues
author: Han Joosten
maintainer: [email protected]
copyright: Han Joosten
Expand All @@ -23,7 +23,7 @@ extra-source-files:

source-repository head
type: git
location: https://github.com/hanjoosten/encodingTest
location: https://github.com/hanjoosten/utf8Guard

library
exposed-modules:
Expand All @@ -32,7 +32,7 @@ library
Types
Util
other-modules:
Paths_encodingTest
Paths_utf8Guard
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
Expand All @@ -41,32 +41,32 @@ library
, rio >=0.1.12.0
default-language: Haskell2010

executable encodingTest-exe
executable utf8Guard
main-is: Main.hs
other-modules:
Paths_encodingTest
Paths_utf8Guard
hs-source-dirs:
app
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.11 && <10
, encodingTest
, optparse-simple
, rio >=0.1.12.0
, utf8Guard
default-language: Haskell2010

test-suite encodingTest-test
test-suite utf8Guard-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
UtilSpec
Paths_encodingTest
Paths_utf8Guard
hs-source-dirs:
test
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.11 && <10
, encodingTest
, hspec
, rio >=0.1.12.0
, utf8Guard
default-language: Haskell2010

0 comments on commit 9b627b0

Please sign in to comment.