Skip to content

Commit

Permalink
Merge pull request #3 from psrenergy/px/rename-project
Browse files Browse the repository at this point in the history
Rename Project
  • Loading branch information
pedromxavier authored Jun 7, 2022
2 parents 648d587 + 670066d commit ebd44c6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "PSREncodings"
name = "Encodings"
uuid = "8275c4fe-57c3-4fbf-b39c-271e6148849a"
authors = ["pedromxavier <[email protected]>"]
version = "0.1.0"
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# PSREncodings
# Encodings

<div align="center">
<a href="/docs/src/assets/">
<img src="/docs/src/assets/logo.svg" width=400px alt="PSREncodings.jl" />
<img src="/docs/src/assets/logo.svg" width=400px alt="Encodings.jl" />
</a>
<br>
<br>
<a href="https://github.com/psrenergy/PSREncodings.jl/actions/workflows/ci.yml">
<img src="https://github.com/psrenergy/PSREncodings.jl/actions/workflows/ci.yml/badge.svg?branch=master" alt="CI" />
<a href="https://github.com/psrenergy/Encodings.jl/actions/workflows/ci.yml">
<img src="https://github.com/psrenergy/Encodings.jl/actions/workflows/ci.yml/badge.svg?branch=master" alt="CI" />
</a>
<a href="https://codecov.io/gh/psrenergy/PSREncodings.jl">
<img src="https://codecov.io/gh/psrenergy/PSREncodings.jl/branch/master/graph/badge.svg?token=0P1MVOMZJ0"/>
<a href="https://codecov.io/gh/psrenergy/Encodings.jl">
<img src="https://codecov.io/gh/psrenergy/Encodings.jl/branch/master/graph/badge.svg?token=0P1MVOMZJ0"/>
</a>
</div>

## Getting Started

### Installation
```julia
julia> ]add https://github.com/psrenergy/PSREncodings.jl#master
julia> ]add https://github.com/psrenergy/Encodings.jl#master
```

### Basic Usage
```julia
julia> using PSREncodings
julia> using Encodings

julia> data = encode("café com pão", ISO_LATIN_1())
12-element Vector{UInt8}:
Expand All @@ -45,23 +45,23 @@ julia> decode(data, ISO_LATIN_1())
```

### Encoding/Decoding Error
`PSREncodings` provides two custom error types: `EncodingError` and `DecodingError`. They are raised when a given encoding doesn't supports some character:
`Encodings` provides two custom error types: `EncodingError` and `DecodingError`. They are raised when a given encoding doesn't supports some character:
```julia
julia> data = encode("μηχανικός means 'engineer' in greek", ISO_LATIN_1())
ERROR: Char 'μ' not available for encoding 'ISO_8859_1'
Stacktrace:
[1] encoding_error(c::Char, e::ISO_8859_1)
@ PSREncodings ~/.julia/packages/PSREncodings/9EX17/src/error.jl:24
@ Encodings ~/.julia/packages/Encodings/9EX17/src/error.jl:24
[2] encode
@ ~/.julia/packages/PSREncodings/9EX17/src/encode.jl:19 [inlined]
@ ~/.julia/packages/Encodings/9EX17/src/encode.jl:19 [inlined]
[3] #3
@ ./none:0 [inlined]
[4] iterate
@ ./generator.jl:47 [inlined]
[5] collect(itr::Base.Generator{String, PSREncodings.var"#3#5"{ISO_8859_1}})
[5] collect(itr::Base.Generator{String, Encodings.var"#3#5"{ISO_8859_1}})
@ Base ./array.jl:724
[6] encode(s::String, e::ISO_8859_1)
@ PSREncodings ~/.julia/packages/PSREncodings/9EX17/src/encode.jl:6
@ Encodings ~/.julia/packages/Encodings/9EX17/src/encode.jl:6
[7] top-level scope
@ REPL[9]:1
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/PSREncodings.jl → src/Encodings.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PSREncodings
module Encodings

export UTF8, ISO_8859_1, ISO_LATIN_1
export encode, decode
Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
using Test
using PSREncodings
using Encodings

text = "Café com pão"
data = UInt8[0x43, 0x61, 0x66, 0xe0, 0x20, 0x63, 0x6f, 0x6d, 0x20, 0x70, 0xe3, 0x6f]

@testset "Encoding :: ISO-LATIN-1" begin
@test encode(text, PSREncodings.ISO_LATIN_1()) == data
@test encode(text, Encodings.ISO_LATIN_1()) == data
end

@testset "Decoding :: ISO-LATIN-1" begin
@test decode(data, PSREncodings.ISO_LATIN_1()) == text
@test decode(data, Encodings.ISO_LATIN_1()) == text
end

text = "The Lorentz factor γ"
data = UInt8[0x54, 0x68, 0x65, 0x20, 0x4c, 0x6f, 0x72, 0x65, 0x6e, 0x74, 0x7a, 0x20, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x3f]

@testset "Encoding Error + Fallback :: ISO-LATIN-1" begin
@test_throws EncodingError encode(text, PSREncodings.ISO_LATIN_1())
@test encode(text, PSREncodings.ISO_LATIN_1(), UInt8('?')) == data
@test_throws EncodingError encode(text, Encodings.ISO_LATIN_1())
@test encode(text, Encodings.ISO_LATIN_1(), UInt8('?')) == data
end

text = "xyz?"
data = UInt8[0x78, 0x79, 0x7a, 0x80]

@testset "Decoding Error + Fallback :: ISO-LATIN-1" begin
@test_throws DecodingError decode(data, PSREncodings.ISO_LATIN_1())
@test decode(data, PSREncodings.ISO_LATIN_1(), Char(0x3f)) == text
@test_throws DecodingError decode(data, Encodings.ISO_LATIN_1())
@test decode(data, Encodings.ISO_LATIN_1(), Char(0x3f)) == text
end

0 comments on commit ebd44c6

Please sign in to comment.