Skip to content

Commit

Permalink
fix: fix multibyte support
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofzablocki committed Dec 22, 2016
1 parent 369c663 commit d2fc38d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Sourcery CHANGELOG

---
## Master

### Bug Fixes
- Fix dealing with multibyte characters

## 0.4.7
### New Features
- Added `contains`, `hasPrefix`, `hasPrefix` filters
Expand Down
2 changes: 1 addition & 1 deletion Sourcery/Parsing/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ extension Parser {

fileprivate func parseAnnotations(_ source: [String: SourceKitRepresentable]) -> Annotations {
guard let range = SubstringIdentifier.key.range(for: source),
let lineInfo = contents.lineAndCharacter(forByteOffset: Int(range.offset)) else { return [:] }
let lineInfo = contents.lineAndCharacter(forCharacterOffset: Int(range.offset)) else { return [:] }

var annotations = Annotations()
for line in lines[0..<lineInfo.line-1].reversed() {
Expand Down
7 changes: 7 additions & 0 deletions SourceryTests/ParserSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ class ParserSpec: QuickSpec {
]))
}

it("extracts multi-byte cases properly") {
expect(parse("enum JapaneseEnum {\ncase アイウエオ\n}"))
.to(equal([
Enum(name: "JapaneseEnum", cases: [Enum.Case(name: "アイウエオ")])
]))
}

it("extracts cases with annotations properly") {
expect(parse("enum Foo {\n // sourcery: annotation\ncase optionA(Int)\n case optionB }"))
.to(equal([
Expand Down

0 comments on commit d2fc38d

Please sign in to comment.