Skip to content

Commit

Permalink
Version 0.1.0.
Browse files Browse the repository at this point in the history
* .gitignore, LICENSE, README.md, shard.yml, spec/nsplist_spec.cr,
spec/spec_helper.cr, src/nsplist.cr: Version 0.1.0.
  • Loading branch information
gemmaro committed Apr 6, 2024
1 parent 2290126 commit 58a4643
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*.cr]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
push:
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Download source
uses: actions/checkout@v2
- name: Install Crystal
uses: crystal-lang/install-crystal@v1
- name: Run tests
run: crystal spec
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf

# Libraries don't need dependency lock
# Dependencies will be locked in applications that use them
/shard.lock
/.crystal/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 your-name-here <your-email-here>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# nsplist

[![GitHub release](https://img.shields.io/github/release/gemmaro/nsplist.svg)](https://github.com/gemmaro/nsplist/releases)

Old-style ASCII property lists parser.

## Installation

1. Add the dependency to your `shard.yml`:

```yaml
dependencies:
nsplist:
github: gemmaro/nsplist
```
2. Run `shards install`

## Usage

```crystal
require "nsplist"
NSPlist.parse(source) #=> property list data
```

## Development

`crystal spec` for testing, and `crystal docs` to generate an API documentation.

## Contributing

1. Fork it (<https://github.com/gemmaro/nsplist/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

## Related Works

There are several related works on the property list parsing. For
parsing the property lists in the XML format, there is a
[plist-cr][xml] libarry.

[xml]: https://github.com/egillet/plist-cr

## Contributors

- [gemmaro](https://github.com/gemmaro) - creator and maintainer
10 changes: 10 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: nsplist
version: 0.1.0
description: nsplist is a Crystal library for parsing the old-style ASCII property lists.

authors:
- gemmaro <[email protected]>

crystal: '>= 1.11.1'

license: MIT
116 changes: 116 additions & 0 deletions spec/nsplist_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
require "./spec_helper"

describe NSPlist do
describe "Crystal standard API" do
it "can use to_u8 with base 16" do
'a'.to_u8(base: 16).should eq(0xa)
end
end

describe "version" do
version = NSPlist::VERSION
version.should be_a(String)
# version.should eq("0.1.0")
end

describe NSPlist::NSString do
it "is compared with String" do
NSPlist::NSString.new("This is a string").should eq("This is a string")
end
end

describe NSPlist::NSData do
it "is compared with Bytes" do
NSPlist::NSData.new(Bytes[0x0f, 0xbd, 0x77, 0x71, 0xc2, 0x73, 0x5a, 0xe]).should eq(Bytes[0x0f, 0xbd, 0x77, 0x71, 0xc2, 0x73, 0x5a, 0xe])
end
end

describe NSPlist::NSArray do
it "can be created from simple array" do
NSPlist::NSArray.new(["San Francisco", "New York"]).should be_a(NSPlist::NSArray)
end
end

describe NSPlist::NSDictionary do
it "can be created from simple hash" do
NSPlist::NSDictionary.new({"user" => "wshakesp", "birth" => "1564"}).should be_a(NSPlist::NSDictionary)
end
end

describe ".parse" do
it "can parse string" do
result = NSPlist.parse(%("This is a string"))
result.should be_a(NSPlist::NSString)
result.should eq("This is a string")
end

it "can parse bare string" do
result = NSPlist.parse("2plus2is5")
result.should be_a(NSPlist::NSString)
result.should eq("2plus2is5")
end

it "can parse quoted string with star" do
result = NSPlist.parse(%("str*ng"))
result.should be_a(NSPlist::NSString)
result.should eq("str*ng")
end

it "can parse binary data" do
binary = "<0fbd777 1c2735ae>"
# 0123456 78901234
# 0 1 2 3 4 5 6 7
result = NSPlist.parse(binary)
result.should be_a(NSPlist::NSData)
result.should eq(Bytes[0x0f, 0xbd, 0x77, 0x71, 0xc2, 0x73, 0x5a, 0xe])
end

it "can parse longer binary data" do
NSPlist.parse("<9aa5d4cd0403c2d990262c15884181da5d1e32ae>").should be_a(NSPlist::NSData)
end

it "can parse array" do
expected = NSPlist::NSArray.new(["San Francisco", "New York"])
result = NSPlist.parse(%{("San Francisco", "New York")})
result.should be_a(NSPlist::NSArray)
result.should eq(expected)
end

it "can parse dictionary" do
expected = NSPlist::NSDictionary.new({"user" => "wshakesp", "birth" => "1564"})
result = NSPlist.parse(%({ user = wshakesp; birth = 1564; }))
result.should be_a(NSPlist::NSDictionary)
result.should eq(expected)
end

it "can parse dictionary, part 2" do
NSPlist.parse("{ pig = piggish; lamb = lambish; worm = wormy; }").should be_a(NSPlist::NSDictionary)
end

it "can parse dictionary of multiple lines" do
NSPlist.parse(%[{ pig = oink; lamb = baa; worm = baa;
Lisa = "Why is the worm talking like a lamb?"; }]).should be_a(NSPlist::NSDictionary)
end

it "can parse complex dictionary" do
NSPlist.parse(%[{
AnimalSmells = { pig = piggish; lamb = lambish; worm = wormy; };
AnimalSounds = { pig = oink; lamb = baa; worm = baa;
Lisa = "Why is the worm talking like a lamb?"; };
AnimalColors = { pig = pink; lamb = black; worm = pink; };
}]).should be_a(NSPlist::NSDictionary)
end

it "can parse dictionary with tabs" do
NSPlist.parse("{
boolean = YES;
integer = 42;
real = 3.14;
}").should be_a(NSPlist::NSDictionary)
end

it "can parse comment" do
NSPlist.parse("/* some * text / here */{ key = value; }").should be_a(NSPlist::NSDictionary)
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "spec"
require "../src/nsplist"
Loading

0 comments on commit 58a4643

Please sign in to comment.