From 9089c117de58c507f87aa75d853cce846cec0048 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 23 May 2020 14:32:40 +0200 Subject: [PATCH] =?UTF-8?q?Initial=20commit!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 + Cargo.toml | 19 +++ License-Apache | 202 +++++++++++++++++++++++ License-MIT | 7 + ReadMe.md | 24 +++ examples/opml_samples/rust_feeds.opml | 9 + examples/rss.rs | 26 +++ rustfmt.toml | 2 + source/lib.rs | 181 ++++++++++++++++++++ tests/errors.rs | 60 +++++++ tests/spec_samples.rs | 23 +++ tests/spec_samples/License | 10 ++ tests/spec_samples/category.opml | 10 ++ tests/spec_samples/directory.opml | 26 +++ tests/spec_samples/placesLived.opml | 43 +++++ tests/spec_samples/simpleScript.opml | 34 ++++ tests/spec_samples/states.opml | 91 ++++++++++ tests/spec_samples/subscriptionList.opml | 31 ++++ tests/valid.rs | 164 ++++++++++++++++++ 19 files changed, 970 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 License-Apache create mode 100644 License-MIT create mode 100644 ReadMe.md create mode 100644 examples/opml_samples/rust_feeds.opml create mode 100644 examples/rss.rs create mode 100644 rustfmt.toml create mode 100644 source/lib.rs create mode 100644 tests/errors.rs create mode 100644 tests/spec_samples.rs create mode 100644 tests/spec_samples/License create mode 100644 tests/spec_samples/category.opml create mode 100644 tests/spec_samples/directory.opml create mode 100644 tests/spec_samples/placesLived.opml create mode 100644 tests/spec_samples/simpleScript.opml create mode 100644 tests/spec_samples/states.opml create mode 100644 tests/spec_samples/subscriptionList.opml create mode 100644 tests/valid.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32fdd69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Compiled files and executables. +/target/ + +# Cargo lockfile. +Cargo.lock + +# Backup files generated by rustfmt. +**/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7bf05b3 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,19 @@ +# https://doc.rust-lang.org/cargo/reference/manifest.html + +[package] +name = "opml" +authors = ["Holllo "] +version = "0.1.0" +license = "MIT/Apache-2.0" +description = "An OPML 2.0 parser for Rust." +repository = "https://gitlab.com/holllo/opml-rs" +readme = "ReadMe.md" +edition = "2018" +keywords = ["xml", "opml"] + +[lib] +path = "source/lib.rs" + +[dependencies] +regex = "1.3.7" +strong-xml = "0.6.0" diff --git a/License-Apache b/License-Apache new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/License-Apache @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/License-MIT b/License-MIT new file mode 100644 index 0000000..ba2c8ec --- /dev/null +++ b/License-MIT @@ -0,0 +1,7 @@ +Copyright 2020 Holllo + +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. diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..1efd92d --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,24 @@ +# OPML + +> An OPML 2.0 parser for Rust. + +## Contents + +* [Examples](examples/) +* [Expertise Wanted](#expertise-wanted) +* [License](#license) + +## Expertise Wanted + +This is the first crate I'm publishing to crates.io and the first proper library I've made for Rust. Any help or tips with how to improve the API, documentation, usability, testing or anything else is very welcome. Feel free to create [an issue](https://gitlab.com/holllo/opml-rs/issues/) or contact me via email at helllo@holllo.cc. + +## License + +Open-sourced with either the + +* [Apache License, Version 2.0](License-Apache) (http://www.apache.org/licenses/LICENSE-2.0) +* [MIT license](License-MIT) (http://opensource.org/licenses/MIT) + +at your option. + +The samples [located in `tests/spec_samples`](tests/spec_samples) were [taken from the OPML 2.0 spec](http://dev.opml.org/spec2.html#examples) and are subject to [their own license](tests/spec_samples/License). diff --git a/examples/opml_samples/rust_feeds.opml b/examples/opml_samples/rust_feeds.opml new file mode 100644 index 0000000..4c5d221 --- /dev/null +++ b/examples/opml_samples/rust_feeds.opml @@ -0,0 +1,9 @@ + + + Rust Feeds + + + + + + diff --git a/examples/rss.rs b/examples/rss.rs new file mode 100644 index 0000000..df01874 --- /dev/null +++ b/examples/rss.rs @@ -0,0 +1,26 @@ +use std::error::Error; +use std::fs; + +use opml::OPML; + +fn main() -> Result<(), Box> { + let xml = fs::read_to_string("examples/opml_samples/rust_feeds.opml")?; + + let subscriptions = OPML::new(&xml)?; + let title = subscriptions.head.title.unwrap(); + + println!(" {}", title); + println!(" {}", "─".repeat(title.len())); + + for outline in subscriptions.body.outlines { + println!(" {}\t{}", outline.text, outline.xml_url.unwrap()); + } + + Ok(()) +} + +// Output: +// Rust Feeds +// ────────── +// Rust Blog https://blog.rust-lang.org/feed.xml +// Inside Rust https://blog.rust-lang.org/inside-rust/feed.xml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..4c1eefa --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 80 +tab_spaces = 2 diff --git a/source/lib.rs b/source/lib.rs new file mode 100644 index 0000000..e0cb5db --- /dev/null +++ b/source/lib.rs @@ -0,0 +1,181 @@ +// TODO: Maybe use a date-time type for all the date-time places? + +use regex::Regex; +use strong_xml::{XmlError, XmlRead, XmlWrite}; + +/// is an XML element, with a single required attribute, version; a element and a element, both of which are required. +#[derive(XmlWrite, XmlRead, PartialEq, Debug)] +#[xml(tag = "opml")] +pub struct OPML { + /// The version attribute is a version string, of the form, x.y, where x and y are both numeric strings. + #[xml(attr = "version")] + pub version: String, + + /// A contains zero or more optional elements. + #[xml(child = "head")] + pub head: Head, + + /// A contains one or more elements. + #[xml(child = "body")] + pub body: Body, +} + +impl OPML { + /// Parses an OPML file. + pub fn new(xml: &str) -> Result { + let opml: Result = OPML::from_str(xml); + + let opml = match opml { + Ok(value) => value, + Err(err) => return Err(format!("XML parsing error: {:#?}", err)), + }; + + // TODO: Maybe implement version 1.0 and 1.1 of the OPML spec? + // SPEC: The version attribute is a version string, of the form, x.y, where x and y are both numeric strings. + let valid_version_regex = Regex::new(r"^\d+\.\d+$").unwrap(); + + if !valid_version_regex.is_match(opml.version.as_str()) + || opml.version != "2.0" + { + return Err(format!( + "Unsupported OPML version detected: {}", + opml.version + )); + } + + // SPEC: A contains one or more elements. + if opml.body.outlines.is_empty() { + return Err("OPML body has no outlines.".to_string()); + } + + Ok(opml) + } +} + +/// A contains zero or more optional elements. +#[derive(XmlWrite, XmlRead, PartialEq, Debug)] +#[xml(tag = "head")] +pub struct Head { + /// The title of the document. + #[xml(flatten_text = "title")] + pub title: Option, + + /// A date-time (RFC822) indicating when the document was created. + #[xml(flatten_text = "dateCreated")] + pub date_created: Option, + + /// A date-time (RFC822) indicating when the document was last modified. + #[xml(flatten_text = "dateModified")] + pub date_modified: Option, + + /// The owner of the document. + #[xml(flatten_text = "ownerName")] + pub owner_name: Option, + + /// The email address of the owner of the document. + #[xml(flatten_text = "ownerEmail")] + pub owner_email: Option, + + /// A link to the website of the owner of the document. + #[xml(flatten_text = "ownerId")] + pub owner_id: Option, + + /// A link to the documentation of the OPML format. + #[xml(flatten_text = "docs")] + pub docs: Option, + + /// A comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + #[xml(flatten_text = "expansionState")] + pub expansion_state: Option, + + /// A number indicating which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + #[xml(flatten_text = "vertScrollState")] + pub vert_scroll_state: Option, + + /// The pixel location of the top edge of the window. + #[xml(flatten_text = "windowTop")] + pub window_top: Option, + + /// The pixel location of the left edge of the window. + #[xml(flatten_text = "windowLeft")] + pub window_left: Option, + + /// The pixel location of the bottom edge of the window. + #[xml(flatten_text = "windowBottom")] + pub window_bottom: Option, + + /// The pixel location of the right edge of the window. + #[xml(flatten_text = "windowRight")] + pub window_right: Option, +} + +/// A contains one or more elements. +#[derive(XmlWrite, XmlRead, PartialEq, Debug)] +#[xml(tag = "body")] +pub struct Body { + /// Child outlines of the body. + #[xml(child = "outline")] + pub outlines: Vec, +} + +/// An is an XML element containing at least one required attribute, text, and zero or more additional attributes. An may contain zero or more sub-elements. No attribute may be repeated within the same element. +#[derive(XmlWrite, XmlRead, PartialEq, Debug)] +#[xml(tag = "outline")] +pub struct Outline { + /// Every outline element must have at least a text attribute, which is what is displayed when an outliner opens the OPML file. + /// Text attributes may contain encoded HTML markup. + #[xml(attr = "text")] + pub text: String, + + /// A string that says how the other attributes of the are interpreted. + #[xml(attr = "type")] + pub r#type: Option, + + /// Indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. + #[xml(default, attr = "isComment")] + pub is_comment: bool, + + /// Indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + #[xml(default, attr = "isBreakpoint")] + pub is_breakpoint: bool, + + /// The date-time (RFC822) that this outline node was created. + #[xml(attr = "created")] + pub created: Option, + + /// A string of comma-separated slash-delimited category strings, in the format defined by the [RSS 2.0 category](http://cyber.law.harvard.edu/rss/rss.html#ltcategorygtSubelementOfLtitemgt) element. To represent a "tag," the category string should contain no slashes. + #[xml(attr = "category")] + pub category: Option, + + /// Child outlines of the current one. + #[xml(child = "outline")] + pub outlines: Vec, + + /// The HTTP address of the feed. + #[xml(attr = "xmlUrl")] + pub xml_url: Option, + + /// The top-level description element from the feed. + #[xml(attr = "description")] + pub description: Option, + + /// The top-level link element from the feed. + #[xml(attr = "htmlUrl")] + pub html_url: Option, + + /// The top-level language element from the feed. + #[xml(attr = "language")] + pub language: Option, + + /// The top-level title element from the feed. + #[xml(attr = "title")] + pub title: Option, + + /// The version of the feed's format (such as RSS 0.91, 2.0, ...). + #[xml(attr = "version")] + pub version: Option, + + /// A link that can point to another OPML file or to something that can be displayed in a web browser. + #[xml(attr = "url")] + pub url: Option, +} diff --git a/tests/errors.rs b/tests/errors.rs new file mode 100644 index 0000000..ac39e1d --- /dev/null +++ b/tests/errors.rs @@ -0,0 +1,60 @@ +// TODO: Extract all the OPML strings out and put them into their own files. + +use opml::*; + +#[test] +#[should_panic] +fn test_invalid_xml() { + OPML::new(r#"{not xml :)"#).unwrap(); +} + +#[test] +#[should_panic(expected = "Unsupported OPML version detected: 1.0")] +fn test_invalid_opml_version_1_0() { + OPML::new( + r#" + + + + + +"#, + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "Unsupported OPML version detected: 1.1")] +fn test_invalid_opml_version_1_1() { + OPML::new( + r#" + + + + + +"#, + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "Unsupported OPML version detected: invalid")] +fn test_invalid_opml_version() { + OPML::new( + r#" + + + + + +"#, + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "OPML body has no outlines.")] +fn test_invalid_opml_no_outlines() { + OPML::new(r#""#).unwrap(); +} diff --git a/tests/spec_samples.rs b/tests/spec_samples.rs new file mode 100644 index 0000000..bc76bdd --- /dev/null +++ b/tests/spec_samples.rs @@ -0,0 +1,23 @@ +use std::error::Error; +use std::fs; + +use opml::*; + +#[test] +pub fn test_spec_samples() -> Result<(), Box> { + let samples = vec![ + "tests/spec_samples/category.opml", + "tests/spec_samples/directory.opml", + "tests/spec_samples/placesLived.opml", + "tests/spec_samples/simpleScript.opml", + "tests/spec_samples/states.opml", + "tests/spec_samples/subscriptionList.opml", + ]; + + for sample in samples { + let sample_content = fs::read_to_string(&sample)?; + OPML::new(sample_content.as_str())?; + } + + Ok(()) +} diff --git a/tests/spec_samples/License b/tests/spec_samples/License new file mode 100644 index 0000000..1859edc --- /dev/null +++ b/tests/spec_samples/License @@ -0,0 +1,10 @@ +© Copyright 2000 UserLand Software, Inc. All Rights Reserved. +© Copyright 2006-2007 Scripting News, Inc. All Rights Reserved. + +UserLand Software, Inc. and Scripting News, Inc. are refererred to in the following as "the Companies." + +This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and these paragraphs are included on all such copies and derivative works. + +This document may not be modified in any way, such as by removing the copyright notice or references to the Companies or other organizations. Further, while these copyright restrictions apply to the written OPML specification, no claim of ownership is made by the Companies to the format it describes. Any party may, for commercial or non-commercial purposes, implement this format without royalty or license fee to the Companies. The limited permissions granted herein are perpetual and will not be revoked by the Companies or their successors or assigns. + +This document and the information contained herein is provided on an "AS IS" basis and THE COMPANIES DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. diff --git a/tests/spec_samples/category.opml b/tests/spec_samples/category.opml new file mode 100644 index 0000000..5121bdc --- /dev/null +++ b/tests/spec_samples/category.opml @@ -0,0 +1,10 @@ + + + + Illustrating the category attribute + Mon, 31 Oct 2005 19:23:00 GMT + + + + + diff --git a/tests/spec_samples/directory.opml b/tests/spec_samples/directory.opml new file mode 100644 index 0000000..230831b --- /dev/null +++ b/tests/spec_samples/directory.opml @@ -0,0 +1,26 @@ + + + + scriptingNewsDirectory.opml + Thu, 13 Oct 2005 15:34:07 GMT + Tue, 25 Oct 2005 21:33:57 GMT + Dave Winer + dwiner@yahoo.com + + 1 + 105 + 466 + 386 + 964 + + + + + + + + + + + + diff --git a/tests/spec_samples/placesLived.opml b/tests/spec_samples/placesLived.opml new file mode 100644 index 0000000..430231b --- /dev/null +++ b/tests/spec_samples/placesLived.opml @@ -0,0 +1,43 @@ + + + + placesLived.opml + Mon, 27 Feb 2006 12:09:48 GMT + Mon, 27 Feb 2006 12:11:44 GMT + Dave Winer + http://www.opml.org/profiles/sendMail?usernum=1 + 1, 2, 5, 10, 13, 15 + 1 + 242 + 329 + 665 + 547 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/spec_samples/simpleScript.opml b/tests/spec_samples/simpleScript.opml new file mode 100644 index 0000000..b0c5612 --- /dev/null +++ b/tests/spec_samples/simpleScript.opml @@ -0,0 +1,34 @@ + + + + workspace.userlandsamples.doSomeUpstreaming + Mon, 11 Feb 2002 22:48:02 GMT + Sun, 30 Oct 2005 03:30:17 GMT + Dave Winer + dwiner@yahoo.com + 1, 2, 4 + 1 + 74 + 41 + 314 + 475 + + + + + + + + + + + + + + + + + + + + diff --git a/tests/spec_samples/states.opml b/tests/spec_samples/states.opml new file mode 100644 index 0000000..360a171 --- /dev/null +++ b/tests/spec_samples/states.opml @@ -0,0 +1,91 @@ + + + + states.opml + Tue, 15 Mar 2005 16:35:45 GMT + Thu, 14 Jul 2005 23:41:05 GMT + Dave Winer + dave@scripting.com + 1, 6, 13, 16, 18, 20 + 1 + 106 + 106 + 558 + 479 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/spec_samples/subscriptionList.opml b/tests/spec_samples/subscriptionList.opml new file mode 100644 index 0000000..457c926 --- /dev/null +++ b/tests/spec_samples/subscriptionList.opml @@ -0,0 +1,31 @@ + + + + mySubscriptions.opml + Sat, 18 Jun 2005 12:11:52 GMT + Tue, 02 Aug 2005 21:42:48 GMT + Dave Winer + dave@scripting.com + + 1 + 61 + 304 + 562 + 842 + + + + + + + + + + + + + + + + + diff --git a/tests/valid.rs b/tests/valid.rs new file mode 100644 index 0000000..7610c7d --- /dev/null +++ b/tests/valid.rs @@ -0,0 +1,164 @@ +// TODO: Extract all the OPML strings out and put them into their own files. + +use opml::*; + +#[test] +fn test_minimum_valid_opml() { + assert_eq!( + OPML::new( + r#" + + + + + +"# + ) + .unwrap(), + OPML { + version: "2.0".to_string(), + head: Head { + title: None, + date_created: None, + date_modified: None, + owner_name: None, + owner_email: None, + owner_id: None, + docs: None, + expansion_state: None, + vert_scroll_state: None, + window_top: None, + window_left: None, + window_bottom: None, + window_right: None, + }, + body: Body { + outlines: vec![Outline { + text: "Outline Text".to_string(), + r#type: None, + is_breakpoint: false, + is_comment: false, + created: None, + category: None, + xml_url: None, + description: None, + html_url: None, + language: None, + title: None, + version: None, + url: None, + outlines: vec![] + }] + }, + } + ); +} + +#[test] +fn test_valid_opml_with_everything() { + assert_eq!( + OPML::new( + r#" + + + Title + Date Created + Date Modified + Owner Name + Owner Email + Owner ID + http://dev.opml.org/spec2.html + 0,1 + 0 + 1 + 2 + 3 + 4 + + + + + + +"# + ) + .unwrap(), + OPML { + version: "2.0".to_string(), + head: Head { + title: Some("Title".to_string()), + date_created: Some("Date Created".to_string()), + date_modified: Some("Date Modified".to_string()), + owner_name: Some("Owner Name".to_string()), + owner_email: Some("Owner Email".to_string()), + owner_id: Some("Owner ID".to_string()), + docs: Some("http://dev.opml.org/spec2.html".to_string()), + expansion_state: Some("0,1".to_string()), + vert_scroll_state: Some(0), + window_top: Some(1), + window_left: Some(2), + window_bottom: Some(3), + window_right: Some(4), + }, + body: Body { + outlines: vec![Outline { + text: "Outline Text".to_string(), + r#type: Some("Outline Type".to_string()), + is_breakpoint: true, + is_comment: true, + created: Some("Outline Date".to_string()), + category: Some("Outline Category".to_string()), + xml_url: Some("Outline XML URL".to_string()), + description: Some("Outline Description".to_string()), + html_url: Some("Outline HTML URL".to_string()), + language: Some("Outline Language".to_string()), + title: Some("Outline Title".to_string()), + version: Some("Outline Version".to_string()), + url: Some("Outline URL".to_string()), + outlines: vec![Outline { + text: "Nested Outline Text".to_string(), + r#type: Some("Nested Outline Type".to_string()), + is_breakpoint: true, + is_comment: false, + created: Some("Nested Outline Date".to_string()), + category: Some("Nested Outline Category".to_string()), + xml_url: Some("Nested Outline XML URL".to_string()), + description: Some("Nested Outline Description".to_string()), + html_url: Some("Nested Outline HTML URL".to_string()), + language: Some("Nested Outline Language".to_string()), + title: Some("Nested Outline Title".to_string()), + version: Some("Nested Outline Version".to_string()), + url: Some("Nested Outline URL".to_string()), + outlines: vec![] + }] + }] + }, + } + ) +}