Initial commit! 🎉

This commit is contained in:
Bauke 2020-05-23 14:32:40 +02:00
commit 9089c117de
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
19 changed files with 970 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Compiled files and executables.
/target/
# Cargo lockfile.
Cargo.lock
# Backup files generated by rustfmt.
**/*.rs.bk

19
Cargo.toml Normal file
View File

@ -0,0 +1,19 @@
# https://doc.rust-lang.org/cargo/reference/manifest.html
[package]
name = "opml"
authors = ["Holllo <helllo@holllo.cc>"]
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"

202
License-Apache Normal file
View File

@ -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.

7
License-MIT Normal file
View File

@ -0,0 +1,7 @@
Copyright 2020 Holllo <helllo@holllo.cc>
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.

24
ReadMe.md Normal file
View File

@ -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).

View File

@ -0,0 +1,9 @@
<opml version="2.0">
<head>
<title>Rust Feeds</title>
</head>
<body>
<outline text="Rust Blog" xmlUrl="https://blog.rust-lang.org/feed.xml" />
<outline text="Inside Rust" xmlUrl="https://blog.rust-lang.org/inside-rust/feed.xml" />
</body>
</opml>

26
examples/rss.rs Normal file
View File

@ -0,0 +1,26 @@
use std::error::Error;
use std::fs;
use opml::OPML;
fn main() -> Result<(), Box<dyn Error>> {
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

2
rustfmt.toml Normal file
View File

@ -0,0 +1,2 @@
max_width = 80
tab_spaces = 2

181
source/lib.rs Normal file
View File

@ -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};
/// <opml> is an XML element, with a single required attribute, version; a <head> element and a <body> 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 <head> contains zero or more optional elements.
#[xml(child = "head")]
pub head: Head,
/// A <body> contains one or more <outline> elements.
#[xml(child = "body")]
pub body: Body,
}
impl OPML {
/// Parses an OPML file.
pub fn new(xml: &str) -> Result<Self, String> {
let opml: Result<OPML, XmlError> = 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 <body> contains one or more <outline> elements.
if opml.body.outlines.is_empty() {
return Err("OPML body has no outlines.".to_string());
}
Ok(opml)
}
}
/// A <head> 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<String>,
/// A date-time (RFC822) indicating when the document was created.
#[xml(flatten_text = "dateCreated")]
pub date_created: Option<String>,
/// A date-time (RFC822) indicating when the document was last modified.
#[xml(flatten_text = "dateModified")]
pub date_modified: Option<String>,
/// The owner of the document.
#[xml(flatten_text = "ownerName")]
pub owner_name: Option<String>,
/// The email address of the owner of the document.
#[xml(flatten_text = "ownerEmail")]
pub owner_email: Option<String>,
/// A link to the website of the owner of the document.
#[xml(flatten_text = "ownerId")]
pub owner_id: Option<String>,
/// A link to the documentation of the OPML format.
#[xml(flatten_text = "docs")]
pub docs: Option<String>,
/// 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<String>,
/// 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<i32>,
/// The pixel location of the top edge of the window.
#[xml(flatten_text = "windowTop")]
pub window_top: Option<i32>,
/// The pixel location of the left edge of the window.
#[xml(flatten_text = "windowLeft")]
pub window_left: Option<i32>,
/// The pixel location of the bottom edge of the window.
#[xml(flatten_text = "windowBottom")]
pub window_bottom: Option<i32>,
/// The pixel location of the right edge of the window.
#[xml(flatten_text = "windowRight")]
pub window_right: Option<i32>,
}
/// A <body> contains one or more <outline> elements.
#[derive(XmlWrite, XmlRead, PartialEq, Debug)]
#[xml(tag = "body")]
pub struct Body {
/// Child outlines of the body.
#[xml(child = "outline")]
pub outlines: Vec<Outline>,
}
/// An <outline> is an XML element containing at least one required attribute, text, and zero or more additional attributes. An <outline> may contain zero or more <outline> sub-elements. No attribute may be repeated within the same <outline> 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 <outline> are interpreted.
#[xml(attr = "type")]
pub r#type: Option<String>,
/// 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<String>,
/// 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<String>,
/// Child outlines of the current one.
#[xml(child = "outline")]
pub outlines: Vec<Outline>,
/// The HTTP address of the feed.
#[xml(attr = "xmlUrl")]
pub xml_url: Option<String>,
/// The top-level description element from the feed.
#[xml(attr = "description")]
pub description: Option<String>,
/// The top-level link element from the feed.
#[xml(attr = "htmlUrl")]
pub html_url: Option<String>,
/// The top-level language element from the feed.
#[xml(attr = "language")]
pub language: Option<String>,
/// The top-level title element from the feed.
#[xml(attr = "title")]
pub title: Option<String>,
/// The version of the feed's format (such as RSS 0.91, 2.0, ...).
#[xml(attr = "version")]
pub version: Option<String>,
/// 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<String>,
}

60
tests/errors.rs Normal file
View File

@ -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#"
<opml version="1.0">
<head/>
<body>
<outline text="Outline Text"/>
</body>
</opml>"#,
)
.unwrap();
}
#[test]
#[should_panic(expected = "Unsupported OPML version detected: 1.1")]
fn test_invalid_opml_version_1_1() {
OPML::new(
r#"
<opml version="1.1">
<head/>
<body>
<outline text="Outline Text"/>
</body>
</opml>"#,
)
.unwrap();
}
#[test]
#[should_panic(expected = "Unsupported OPML version detected: invalid")]
fn test_invalid_opml_version() {
OPML::new(
r#"
<opml version="invalid">
<head/>
<body>
<outline text="Outline Text"/>
</body>
</opml>"#,
)
.unwrap();
}
#[test]
#[should_panic(expected = "OPML body has no outlines.")]
fn test_invalid_opml_no_outlines() {
OPML::new(r#"<opml version="2.0"><head/><body/></opml>"#).unwrap();
}

23
tests/spec_samples.rs Normal file
View File

@ -0,0 +1,23 @@
use std::error::Error;
use std::fs;
use opml::*;
#[test]
pub fn test_spec_samples() -> Result<(), Box<dyn Error>> {
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(())
}

View File

@ -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.

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>Illustrating the category attribute</title>
<dateCreated>Mon, 31 Oct 2005 19:23:00 GMT</dateCreated>
</head>
<body>
<outline text="The Mets are the best team in baseball." category="/Philosophy/Baseball/Mets,/Tourism/New York" created="Mon, 31 Oct 2005 18:21:33 GMT"/>
</body>
</opml>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>scriptingNewsDirectory.opml</title>
<dateCreated>Thu, 13 Oct 2005 15:34:07 GMT</dateCreated>
<dateModified>Tue, 25 Oct 2005 21:33:57 GMT</dateModified>
<ownerName>Dave Winer</ownerName>
<ownerEmail>dwiner@yahoo.com</ownerEmail>
<expansionState></expansionState>
<vertScrollState>1</vertScrollState>
<windowTop>105</windowTop>
<windowLeft>466</windowLeft>
<windowBottom>386</windowBottom>
<windowRight>964</windowRight>
</head>
<body>
<outline text="Scripting News sites" created="Sun, 16 Oct 2005 05:56:10 GMT" type="link" url="http://hosting.opml.org/dave/mySites.opml"/>
<outline text="News.Com top 100 OPML" created="Tue, 25 Oct 2005 21:33:28 GMT" type="link" url="http://news.com.com/html/ne/blogs/CNETNewsBlog100.opml"/>
<outline text="BloggerCon III Blogroll" created="Mon, 24 Oct 2005 05:23:52 GMT" type="link" url="http://static.bloggercon.org/iii/blogroll.opml"/>
<outline text="TechCrunch reviews" type="link" url="http://hosting.opml.org/techcrunch.opml.org/TechCrunch.opml"/>
<outline text="Tod Maffin's directory of Public Radio podcasts" type="link" url="http://todmaffin.com/radio.opml"/>
<outline text="Adam Curry's iPodder.org directory" type="link" url="http://homepage.mac.com/dailysourcecode/DSC/ipodderDirectory.opml"/>
<outline text="Memeorandum" created="Thu, 13 Oct 2005 15:19:05 GMT" type="link" url="http://tech.memeorandum.com/index.opml"/>
<outline text="DaveNet archive" created="Wed, 12 Oct 2005 01:39:56 GMT" type="link" url="http://davenet.opml.org/index.opml"/>
</body>
</opml>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>placesLived.opml</title>
<dateCreated>Mon, 27 Feb 2006 12:09:48 GMT</dateCreated>
<dateModified>Mon, 27 Feb 2006 12:11:44 GMT</dateModified>
<ownerName>Dave Winer</ownerName>
<ownerId>http://www.opml.org/profiles/sendMail?usernum=1</ownerId>
<expansionState>1, 2, 5, 10, 13, 15</expansionState>
<vertScrollState>1</vertScrollState>
<windowTop>242</windowTop>
<windowLeft>329</windowLeft>
<windowBottom>665</windowBottom>
<windowRight>547</windowRight>
</head>
<body>
<outline text="Places I've lived">
<outline text="Boston">
<outline text="Cambridge"/>
<outline text="West Newton"/>
</outline>
<outline text="Bay Area">
<outline text="Mountain View"/>
<outline text="Los Gatos"/>
<outline text="Palo Alto"/>
<outline text="Woodside"/>
</outline>
<outline text="New Orleans">
<outline text="Uptown"/>
<outline text="Metairie"/>
</outline>
<outline text="Wisconsin">
<outline text="Madison"/>
</outline>
<outline text="Florida" type="include" url="http://hosting.opml.org/dave/florida.opml"/>
<outline text="New York">
<outline text="Jackson Heights"/>
<outline text="Flushing"/>
<outline text="The Bronx"/>
</outline>
</outline>
</body>
</opml>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>workspace.userlandsamples.doSomeUpstreaming</title>
<dateCreated>Mon, 11 Feb 2002 22:48:02 GMT</dateCreated>
<dateModified>Sun, 30 Oct 2005 03:30:17 GMT</dateModified>
<ownerName>Dave Winer</ownerName>
<ownerEmail>dwiner@yahoo.com</ownerEmail>
<expansionState>1, 2, 4</expansionState>
<vertScrollState>1</vertScrollState>
<windowTop>74</windowTop>
<windowLeft>41</windowLeft>
<windowBottom>314</windowBottom>
<windowRight>475</windowRight>
</head>
<body>
<outline text="Changes" isComment="true">
<outline text="1/3/02; 4:54:25 PM by DW">
<outline text="Change &quot;playlist&quot; to &quot;radio&quot;."/>
</outline>
<outline text="2/12/01; 1:49:33 PM by DW" isComment="true">
<outline text="Test upstreaming by sprinkling a few files in a nice new test folder."/>
</outline>
</outline>
<outline text="on writetestfile (f, size)">
<outline text="file.surefilepath (f)" isBreakpoint="true"/>
<outline text="file.writewholefile (f, string.filledstring (&quot;x&quot;, size))"/>
</outline>
<outline text="local (folder = user.radio.prefs.wwwfolder + &quot;test\\largefiles\\&quot;)"/>
<outline text="for ch = 'a' to 'z'">
<outline text="writetestfile (folder + ch + &quot;.html&quot;, random (1000, 16000))"/>
</outline>
</body>
</opml>

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>states.opml</title>
<dateCreated>Tue, 15 Mar 2005 16:35:45 GMT</dateCreated>
<dateModified>Thu, 14 Jul 2005 23:41:05 GMT</dateModified>
<ownerName>Dave Winer</ownerName>
<ownerEmail>dave@scripting.com</ownerEmail>
<expansionState>1, 6, 13, 16, 18, 20</expansionState>
<vertScrollState>1</vertScrollState>
<windowTop>106</windowTop>
<windowLeft>106</windowLeft>
<windowBottom>558</windowBottom>
<windowRight>479</windowRight>
</head>
<body>
<outline text="United States">
<outline text="Far West">
<outline text="Alaska"/>
<outline text="California"/>
<outline text="Hawaii"/>
<outline text="Nevada">
<outline text="Reno" created="Tue, 12 Jul 2005 23:56:35 GMT"/>
<outline text="Las Vegas" created="Tue, 12 Jul 2005 23:56:37 GMT"/>
<outline text="Ely" created="Tue, 12 Jul 2005 23:56:39 GMT"/>
<outline text="Gerlach" created="Tue, 12 Jul 2005 23:56:47 GMT"/>
</outline>
<outline text="Oregon"/>
<outline text="Washington"/>
</outline>
<outline text="Great Plains">
<outline text="Kansas"/>
<outline text="Nebraska"/>
<outline text="North Dakota"/>
<outline text="Oklahoma"/>
<outline text="South Dakota"/>
</outline>
<outline text="Mid-Atlantic">
<outline text="Delaware"/>
<outline text="Maryland"/>
<outline text="New Jersey"/>
<outline text="New York"/>
<outline text="Pennsylvania"/>
</outline>
<outline text="Midwest">
<outline text="Illinois"/>
<outline text="Indiana"/>
<outline text="Iowa"/>
<outline text="Kentucky"/>
<outline text="Michigan"/>
<outline text="Minnesota"/>
<outline text="Missouri"/>
<outline text="Ohio"/>
<outline text="West Virginia"/>
<outline text="Wisconsin"/>
</outline>
<outline text="Mountains">
<outline text="Colorado"/>
<outline text="Idaho"/>
<outline text="Montana"/>
<outline text="Utah"/>
<outline text="Wyoming"/>
</outline>
<outline text="New England">
<outline text="Connecticut"/>
<outline text="Maine"/>
<outline text="Massachusetts"/>
<outline text="New Hampshire"/>
<outline text="Rhode Island"/>
<outline text="Vermont"/>
</outline>
<outline text="South">
<outline text="Alabama"/>
<outline text="Arkansas"/>
<outline text="Florida"/>
<outline text="Georgia"/>
<outline text="Louisiana"/>
<outline text="Mississippi"/>
<outline text="North Carolina"/>
<outline text="South Carolina"/>
<outline text="Tennessee"/>
<outline text="Virginia"/>
</outline>
<outline text="Southwest">
<outline text="Arizona"/>
<outline text="New Mexico"/>
<outline text="Texas"/>
</outline>
</outline>
</body>
</opml>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>mySubscriptions.opml</title>
<dateCreated>Sat, 18 Jun 2005 12:11:52 GMT</dateCreated>
<dateModified>Tue, 02 Aug 2005 21:42:48 GMT</dateModified>
<ownerName>Dave Winer</ownerName>
<ownerEmail>dave@scripting.com</ownerEmail>
<expansionState></expansionState>
<vertScrollState>1</vertScrollState>
<windowTop>61</windowTop>
<windowLeft>304</windowLeft>
<windowBottom>562</windowBottom>
<windowRight>842</windowRight>
</head>
<body>
<outline text="CNET News.com" description="Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media." htmlUrl="http://news.com.com/" language="unknown" title="CNET News.com" type="rss" version="RSS2" xmlUrl="http://news.com.com/2547-1_3-0-5.xml"/>
<outline text="washingtonpost.com - Politics" description="Politics" htmlUrl="http://www.washingtonpost.com/wp-dyn/politics?nav=rss_politics" language="unknown" title="washingtonpost.com - Politics" type="rss" version="RSS2" xmlUrl="http://www.washingtonpost.com/wp-srv/politics/rssheadlines.xml"/>
<outline text="Scobleizer: Microsoft Geek Blogger" description="Robert Scoble's look at geek and Microsoft life." htmlUrl="http://radio.weblogs.com/0001011/" language="unknown" title="Scobleizer: Microsoft Geek Blogger" type="rss" version="RSS2" xmlUrl="http://radio.weblogs.com/0001011/rss.xml"/>
<outline text="Yahoo! News: Technology" description="Technology" htmlUrl="http://news.yahoo.com/news?tmpl=index&amp;cid=738" language="unknown" title="Yahoo! News: Technology" type="rss" version="RSS2" xmlUrl="http://rss.news.yahoo.com/rss/tech"/>
<outline text="Workbench" description="Programming and publishing news and comment" htmlUrl="http://www.cadenhead.org/workbench/" language="unknown" title="Workbench" type="rss" version="RSS2" xmlUrl="http://www.cadenhead.org/workbench/rss.xml"/>
<outline text="Christian Science Monitor | Top Stories" description="Read the front page stories of csmonitor.com." htmlUrl="http://csmonitor.com" language="unknown" title="Christian Science Monitor | Top Stories" type="rss" version="RSS" xmlUrl="http://www.csmonitor.com/rss/top.rss"/>
<outline text="Dictionary.com Word of the Day" description="A new word is presented every day with its definition and example sentences from actual published works." htmlUrl="http://dictionary.reference.com/wordoftheday/" language="unknown" title="Dictionary.com Word of the Day" type="rss" version="RSS" xmlUrl="http://www.dictionary.com/wordoftheday/wotd.rss"/>
<outline text="The Motley Fool" description="To Educate, Amuse, and Enrich" htmlUrl="http://www.fool.com" language="unknown" title="The Motley Fool" type="rss" version="RSS" xmlUrl="http://www.fool.com/xml/foolnews_rss091.xml"/>
<outline text="InfoWorld: Top News" description="The latest on Top News from InfoWorld" htmlUrl="http://www.infoworld.com/news/index.html" language="unknown" title="InfoWorld: Top News" type="rss" version="RSS2" xmlUrl="http://www.infoworld.com/rss/news.xml"/>
<outline text="NYT &gt; Business" description="Find breaking news &amp; business news on Wall Street, media &amp; advertising, international business, banking, interest rates, the stock market, currencies &amp; funds." htmlUrl="http://www.nytimes.com/pages/business/index.html?partner=rssnyt" language="unknown" title="NYT &gt; Business" type="rss" version="RSS2" xmlUrl="http://www.nytimes.com/services/xml/rss/nyt/Business.xml"/>
<outline text="NYT &gt; Technology" description="" htmlUrl="http://www.nytimes.com/pages/technology/index.html?partner=rssnyt" language="unknown" title="NYT &gt; Technology" type="rss" version="RSS2" xmlUrl="http://www.nytimes.com/services/xml/rss/nyt/Technology.xml"/>
<outline text="Scripting News" description="It's even worse than it appears." htmlUrl="http://www.scripting.com/" language="unknown" title="Scripting News" type="rss" version="RSS2" xmlUrl="http://www.scripting.com/rss.xml"/>
<outline text="Wired News" description="Technology, and the way we do business, is changing the world we know. Wired News is a technology - and business-oriented news service feeding an intelligent, discerning audience. What role does technology play in the day-to-day living of your life? Wired News tells you. How has evolving technology changed the face of the international business world? Wired News puts you in the picture." htmlUrl="http://www.wired.com/" language="unknown" title="Wired News" type="rss" version="RSS" xmlUrl="http://www.wired.com/news_drop/netcenter/netcenter.rdf"/>
</body>
</opml>

164
tests/valid.rs Normal file
View File

@ -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#"
<opml version="2.0">
<head/>
<body>
<outline text="Outline Text"/>
</body>
</opml>"#
)
.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#"
<opml version="2.0">
<head>
<title>Title</title>
<dateCreated>Date Created</dateCreated>
<dateModified>Date Modified</dateModified>
<ownerName>Owner Name</ownerName>
<ownerEmail>Owner Email</ownerEmail>
<ownerId>Owner ID</ownerId>
<docs>http://dev.opml.org/spec2.html</docs>
<expansionState>0,1</expansionState>
<vertScrollState>0</vertScrollState>
<windowTop>1</windowTop>
<windowLeft>2</windowLeft>
<windowBottom>3</windowBottom>
<windowRight>4</windowRight>
</head>
<body>
<outline
text="Outline Text"
type="Outline Type"
isBreakpoint="true"
isComment="true"
created="Outline Date"
category="Outline Category"
xmlUrl="Outline XML URL"
description="Outline Description"
htmlUrl="Outline HTML URL"
language="Outline Language"
title="Outline Title"
version="Outline Version"
url="Outline URL">
<outline
text="Nested Outline Text"
type="Nested Outline Type"
isBreakpoint="true"
isComment="false"
created="Nested Outline Date"
category="Nested Outline Category"
xmlUrl="Nested Outline XML URL"
description="Nested Outline Description"
htmlUrl="Nested Outline HTML URL"
language="Nested Outline Language"
title="Nested Outline Title"
version="Nested Outline Version"
url="Nested Outline URL"/>
</outline>
</body>
</opml>"#
)
.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![]
}]
}]
},
}
)
}