[Git][clojure-team/clj-yaml-clojure][master] 13 commits: New upstream version 0.7.0
Louis-Philippe Véronneau
gitlab at salsa.debian.org
Tue Sep 1 07:04:51 BST 2020
Louis-Philippe Véronneau pushed to branch master at Debian Clojure Maintainers / clj-yaml-clojure
Commits:
2f2467dd by Louis-Philippe Véronneau at 2020-09-01T02:04:27-04:00
New upstream version 0.7.0
- - - - -
ca638636 by Louis-Philippe Véronneau at 2020-09-01T02:04:27-04:00
New upstream version. (Closes: #964222)
- - - - -
5d736afa by Louis-Philippe Véronneau at 2020-09-01T02:04:27-04:00
d/watch: create a watch file.
- - - - -
af9397c4 by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
d/control: updates standards to 4.5.0.0 (no changes required).
- - - - -
cdd41dc6 by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
d/control: use debhelper 13.
- - - - -
b3198db4 by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
d/rules: simplify by not rendering md to html.
- - - - -
cfdc6c17 by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
d/control: update dependencies.
- - - - -
b1f3769b by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
d/pom.xml: update.
- - - - -
9db3b44f by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
d/rules: compile java bits to bytecode.
- - - - -
c1a09683 by Louis-Philippe Véronneau at 2020-09-01T02:04:28-04:00
New maintainer: pollo is taking over this package.
- - - - -
10bb322f by Louis-Philippe Véronneau at 2020-09-01T02:04:29-04:00
d/control: update VCS fields and upstream homepage.
- - - - -
898ae307 by Louis-Philippe Véronneau at 2020-09-01T02:04:29-04:00
d/control: move the package from the Java Team to the Clojure Team.
- - - - -
289a838f by Louis-Philippe Véronneau at 2020-09-01T02:04:29-04:00
d/tests: add autopkgtests.
- - - - -
22 changed files:
- + .circleci/config.yml
- .gitignore
- + CHANGELOG.md
- README.md
- debian/changelog
- − debian/compat
- debian/control
- debian/copyright
- − debian/footer.html
- − debian/header.html
- + debian/libclj-yaml-clojure.classpath
- debian/pom.xml
- debian/rules
- + debian/tests/build
- + debian/tests/control
- + debian/tests/unittests
- + debian/watch
- project.clj
- − src/clj_yaml/core.clj
- + src/clojure/clj_yaml/core.clj
- + src/java/clj_yaml/MarkedConstructor.java
- test/clj_yaml/core_test.clj
Changes:
=====================================
.circleci/config.yml
=====================================
@@ -0,0 +1,17 @@
+version: 2.1
+jobs:
+ test:
+ docker:
+ - image: circleci/clojure:lein-2.8.1
+ steps:
+ - checkout
+ - run:
+ name: Ensure No Reflection Warnings
+ command: "! lein check 2>&1 | grep 'Reflection warning'"
+ - run: lein test
+
+
+workflows:
+ workflow:
+ jobs:
+ - test
=====================================
.gitignore
=====================================
@@ -1,5 +1,6 @@
+bin
lib
classes
*.jar
-.*
-pom.xml
+pom.xml*
+/target
=====================================
CHANGELOG.md
=====================================
@@ -0,0 +1,17 @@
+# Changelog
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
+
+## [0.7.0] - 2019-03-15
+### Changed
+- [Accept emoji](https://github.com/clj-commons/clj-yaml/pull/5).
+- [Update to SnakeYAML from 1.23 to 1.24](https://github.com/clj-commons/clj-yaml/pull/5).
+
+## [0.6.1] - 2019-02-06
+### Changed
+- [Restore default text-wrapping behavior of prior release](https://github.com/clj-commons/clj-yaml/pull/2).
+
+## [0.6.0] - 2019-01-04
+### Added
+- First release under [clj-commons](https://github.com/clj-commons) project.
=====================================
README.md
=====================================
@@ -1,9 +1,21 @@
-`clj-yaml` provides [YAML](http://yaml.org) encoding and decoding for Clojure via the [SnakeYAML](http://code.google.com/p/snakeyaml/) Java library.
+`clj-commons/clj-yaml` provides [YAML](http://yaml.org) encoding and
+decoding for Clojure via the [snakeyaml][] Java library.
+
+[SnakeYAML]: https://bitbucket.org/asomov/snakeyaml/
+
+
+[![Clojars Project](https://img.shields.io/clojars/v/clj-commons/clj-yaml.svg)](https://clojars.org/clj-commons/clj-yaml) [![cljdoc badge](https://cljdoc.org/badge/clj-commons/clj-yaml)](https://cljdoc.org/d/clj-commons/clj-yaml/CURRENT)
+ [![CircleCI Status](https://circleci.com/gh/clj-commons/clj-yaml.svg?style=svg)](https://circleci.com/gh/clj-commons/clj-yaml)
+
+(This is a maintained fork of [the original][]).
+
+[the original]: https://github.com/lancepantz/clj-yaml
+
## Usage
(require '[clj-yaml.core :as yaml])
-
+
(yaml/generate-string
[{:name "John Smith", :age 33}
{:name "Mary Smith", :age 27}])
@@ -17,17 +29,32 @@
=> ({:name "John Smith", :age 33}
{:name "Mary Smith", :age 27})
+By default, keys are converted to clojure keywords. To prevent this,
+add `:keywords false` parameters to the `parse-string` function:
+
+ (yaml/parse-string "
+ - {name: John Smith}
+ " :keywords false)
+
## Installation
-`clj-yaml` is available as a Maven artifact from [Clojars](http://clojars.org/clj-yaml):
+`clj-commons/clj-yaml` is available as a Maven artifact from [Clojars](http://clojars.org/clj-commons/clj-yaml).
+
+### Leiningen/Boot
+
+```clojure
+[clj-commons/clj-yaml "0.6.0"]
+```
+
+### Clojure CLI/`deps.edn`
- :dependencies
- [["clj-yaml" "0.4.0"]
- ...]
+```clojure
+clj-commons/clj-yaml {:mvn/version "0.6.0"}
+```
## Development
- $ git clone git://github.com/lancepantz/clj-yaml.git
+ $ git clone git://github.com/clj-commons/clj-yaml.git
$ lein deps
$ lein test
$ lein install
=====================================
debian/changelog
=====================================
@@ -1,3 +1,20 @@
+clj-yaml-clojure (0.7.0-1) UNRELEASED; urgency=medium
+
+ * New maintainer: pollo is taking over this package.
+ * New upstream version. (Closes: #964222)
+ * d/watch: create a watch file.
+ * d/control: updates standards to 4.5.0.0 (no changes required).
+ * d/control: use debhelper 13.
+ * d/rules: simplify by not rendering md to html.
+ * d/control: update dependencies.
+ * d/pom.xml: update.
+ * d/rules: compile java bits to bytecode.
+ * d/control: update VCS fields and upstream homepage.
+ * d/control: move the package from the Java Team to the Clojure Team.
+ * d/tests: add autopkgtests.
+
+ -- Louis-Philippe Véronneau <pollo at debian.org> Fri, 28 Aug 2020 18:31:50 -0400
+
clj-yaml-clojure (0.4.0-1) unstable; urgency=medium
* Initial release (Closes: #855715)
=====================================
debian/compat deleted
=====================================
@@ -1 +0,0 @@
-10
=====================================
debian/control
=====================================
@@ -1,26 +1,29 @@
Source: clj-yaml-clojure
Section: java
Priority: optional
-Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.org>
-Uploaders: Apollon Oikonomopoulos <apoikos at debian.org>
+Maintainer: Debian Clojure Maintainers <pkg-clojure-maintainers at lists.alioth.debian.org>
+Uploaders: Louis-Philippe Véronneau <pollo at debian.org>
Build-Depends:
- debhelper (>= 10),
- javahelper (>= 0.32),
- maven-repo-helper (>= 1.7),
- clojure (>= 1.8),
- libyaml-snake-java (>= 1.5),
- libtext-markdown-perl | markdown,
- default-jdk
-Standards-Version: 4.0.0
-Vcs-Git: https://anonscm.debian.org/git/pkg-java/clj-yaml-clojure.git
-Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/clj-yaml-clojure.git
-Homepage: https://github.com/lancepantz/clj-yaml
+ debhelper-compat (= 13),
+ javahelper,
+ maven-repo-helper,
+ clojure,
+ default-jdk,
+ libyaml-snake-java <!nocheck>,
+ libordered-clojure <!nocheck>,
+Standards-Version: 4.5.0.0
+Vcs-Browser: https://salsa.debian.org/clojure-team/cli-yaml-clojure
+Vcs-Git: https://salsa.debian.org/clojure-team/cli-yaml-clojure.git
+Homepage: https://github.com/clj-commons/clj-yaml
+Rules-Requires-Root: no
Package: libclj-yaml-clojure
Architecture: all
Depends:
${java:Depends},
- ${misc:Depends}
+ ${misc:Depends},
+ libyaml-snake-java,
+ libordered-clojure,
Recommends: ${java:Recommends}
Description: YAML encoding and decoding for Clojure
clj-yaml provides YAML encoding and decoding for Clojure via the SnakeYAML
=====================================
debian/copyright
=====================================
@@ -228,6 +228,7 @@ License: EPL-1
Files: debian/*
Copyright: 2017 Apollon Oikonomopoulos <apoikos at debian.org>
+ 2020, Louis-Philippe Véronneau <pollo at debian.org>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
=====================================
debian/footer.html deleted
=====================================
@@ -1,2 +0,0 @@
-</body>
-</html>
=====================================
debian/header.html deleted
=====================================
@@ -1,6 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html>
-<head>
-<title>@TITLE@</title>
-</head>
-<body>
=====================================
debian/libclj-yaml-clojure.classpath
=====================================
@@ -0,0 +1 @@
+/usr/share/java/clj-yaml.jar /usr/share/java/clojure.jar
=====================================
debian/pom.xml
=====================================
@@ -1,19 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>clj-yaml</groupId>
+ <groupId>clj-commons</groupId>
<artifactId>clj-yaml</artifactId>
<packaging>jar</packaging>
- <version>0.4.0</version>
+ <version>0.7.0</version>
<name>clj-yaml</name>
<description>YAML encoding and decoding for Clojure using SnakeYAML</description>
- <url>http://github.com/lancepantz/clj-yaml</url>
+ <url>https://github.com/clj-commons/clj-yaml</url>
+ <licenses>
+ <license>
+ <name>Eclipse Public License - v 1.0</name>
+ <url>http://www.eclipse.org/legal/epl-v10.html</url>
+ <distribution>repo</distribution>
+ <comments>same as Clojure</comments>
+ </license>
+ </licenses>
<scm>
- <tag>2dc440aa2016165aabb16408d17f523dee403c8f
-</tag>
- <url/>
+ <tag>d57bcb223c94aec59cf81ad0bb673d86b5694ca6</tag>
</scm>
<build>
- <sourceDirectory>src</sourceDirectory>
+ <sourceDirectory>src/clojure</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
@@ -27,7 +33,27 @@
</testResources>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
- <plugins/>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
</build>
<repositories>
<repository>
@@ -42,7 +68,7 @@
</repository>
<repository>
<id>clojars</id>
- <url>https://clojars.org/repo/</url>
+ <url>https://repo.clojars.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
@@ -58,12 +84,17 @@
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
- <version>1.2.0</version>
+ <version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
- <version>1.5</version>
+ <version>1.24</version>
+ </dependency>
+ <dependency>
+ <groupId>org.flatland</groupId>
+ <artifactId>ordered</artifactId>
+ <version>1.5.7</version>
</dependency>
</dependencies>
</project>
=====================================
debian/rules
=====================================
@@ -2,17 +2,15 @@
include /usr/share/javahelper/java-vars.mk
-MDWN_DOCS = $(patsubst %.md,%.html,$(wildcard $(CURDIR)/*.md))
-
PRODUCED_JAR=clj-yaml.jar
-export CLASSPATH=/usr/share/java/clojure.jar:/usr/share/java/snakeyaml.jar
+export CLASSPATH=/usr/share/java/clojure.jar:/usr/share/java/snakeyaml.jar:/usr/share/java/ordered.jar
%:
dh $@ --with javahelper --with jh_maven_repo_helper
-override_jh_build: $(MDWN_DOCS)
- jar cf $(PRODUCED_JAR) -C src .
- mkdir -p $(CURDIR)/doc/html && mv $(CURDIR)/*.html $(CURDIR)/doc/html
+override_jh_build:
+ jh_build --no-javadoc $(PRODUCED_JAR) src/java
+ jar uf $(PRODUCED_JAR) -C src/clojure .
override_jh_classpath:
jh_classpath $(PRODUCED_JAR)
@@ -20,13 +18,6 @@ override_jh_classpath:
override_jh_clean:
jh_clean
rm -f $(CURDIR)/$(PRODUCED_JAR)
- rm -rf $(CURDIR)/doc/html
-
-%.html:%.md
- cat debian/header.html > $@
- sed -i'' -e 's#@TITLE@#$(shell head -n 1 $< | sed 's/^#*\s*//')#g' $@
- markdown $< >> $@
- cat debian/footer.html >> $@
override_dh_auto_test:
dh_auto_test
=====================================
debian/tests/build
=====================================
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+CLASSPATH=/usr/share/java/clojure.jar:/usr/share/java/snakeyaml.jar:/usr/share/java/ordered.jar:/usr/share/java/clj-yaml.jar
+
+clojure -cp $CLASSPATH -e '(use '"'"'clj-yaml.core)'
=====================================
debian/tests/control
=====================================
@@ -0,0 +1,6 @@
+Tests: build
+Depends: @, clojure
+Restrictions: superficial
+
+Tests: unittests
+Depends: @, clojure
=====================================
debian/tests/unittests
=====================================
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -efu
+
+CLASSPATH=/usr/share/java/clojure.jar:/usr/share/java/snakeyaml.jar:/usr/share/java/ordered.jar:/usr/share/java/clj-yaml.jar
+
+cp -a test "$AUTOPKGTEST_TMP"
+cd "$AUTOPKGTEST_TMP"
+
+find . -name "*.clj" | xargs clojure -cp $CLASSPATH
=====================================
debian/watch
=====================================
@@ -0,0 +1,4 @@
+version=4
+opts="mode=git, uversionmangle=s/Release-\.//" \
+https://github.com/clj-commons/clj-yaml \
+refs/tags/(Release-)?([\d\.]+)
=====================================
project.clj
=====================================
@@ -1,6 +1,16 @@
-(defproject clj-yaml "0.4.0"
+(defproject clj-commons/clj-yaml "0.7.0"
:description "YAML encoding and decoding for Clojure using SnakeYAML"
- :url "http://github.com/lancepantz/clj-yaml"
+ :url "https://github.com/clj-commons/clj-yaml"
+ :license {:name "Eclipse Public License - v 1.0"
+ :url "http://www.eclipse.org/legal/epl-v10.html"
+ :distribution :repo
+ :comments "same as Clojure"}
+ ;; Emit warnings on all reflection calls.
+ :global-vars {*warn-on-reflection* true}
+ :source-paths ["src/clojure"]
+ :java-source-paths ["src/java"]
+ :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"]
:dependencies
- [[org.clojure/clojure "1.2.0"]
- [org.yaml/snakeyaml "1.5"]])
+ [[org.clojure/clojure "1.7.0"]
+ [org.yaml/snakeyaml "1.24"]
+ [org.flatland/ordered "1.5.7"]])
=====================================
src/clj_yaml/core.clj deleted
=====================================
@@ -1,78 +0,0 @@
-(ns clj-yaml.core
- (:import (org.yaml.snakeyaml Yaml DumperOptions DumperOptions$FlowStyle)))
-
-(def ^{:dynamic true} *keywordize* true)
-
-(def flow-styles
- {:auto DumperOptions$FlowStyle/AUTO
- :block DumperOptions$FlowStyle/BLOCK
- :flow DumperOptions$FlowStyle/FLOW})
-
-(defn make-dumper-options
- [& {:keys [flow-style]}]
- (doto (DumperOptions.)
- (.setDefaultFlowStyle (flow-styles flow-style))))
-
-(defn make-yaml
- [& {:keys [dumper-options]}]
- (if dumper-options
- (Yaml. (apply make-dumper-options
- (mapcat (juxt key val)
- dumper-options)))
- (Yaml.)))
-
-(defprotocol YAMLCodec
- (encode [data])
- (decode [data]))
-
-(defn decode-key [k]
- (if *keywordize* (keyword k) k))
-
-(extend-protocol YAMLCodec
-
- clojure.lang.IPersistentMap
- (encode [data]
- (into {}
- (for [[k v] data]
- [(encode k) (encode v)])))
-
- clojure.lang.IPersistentCollection
- (encode [data]
- (map encode data))
-
- clojure.lang.Keyword
- (encode [data]
- (name data))
-
- java.util.LinkedHashMap
- (decode [data]
- (into {}
- (for [[k v] data]
- [(decode-key k) (decode v)])))
-
- java.util.LinkedHashSet
- (decode [data]
- (into #{} data))
-
- java.util.ArrayList
- (decode [data]
- (map decode data))
-
- Object
- (encode [data] data)
- (decode [data] data)
-
- nil
- (encode [data] data)
- (decode [data] data))
-
-(defn generate-string [data & opts]
- (.dump (apply make-yaml opts)
- (encode data)))
-
-(defn parse-string
- ([string keywordize]
- (binding [*keywordize* keywordize]
- (parse-string string)))
- ([string]
- (decode (.load (make-yaml) string))))
=====================================
src/clojure/clj_yaml/core.clj
=====================================
@@ -0,0 +1,130 @@
+(ns clj-yaml.core
+ (:require [flatland.ordered.map :refer (ordered-map)]
+ [flatland.ordered.set :refer (ordered-set)])
+ (:import (org.yaml.snakeyaml Yaml DumperOptions DumperOptions$FlowStyle)
+ (org.yaml.snakeyaml.constructor Constructor SafeConstructor BaseConstructor)
+ (org.yaml.snakeyaml.representer Representer)
+ (org.yaml.snakeyaml.error Mark)
+ (clj_yaml MarkedConstructor)
+ (java.util LinkedHashMap)))
+
+(def flow-styles
+ {:auto DumperOptions$FlowStyle/AUTO
+ :block DumperOptions$FlowStyle/BLOCK
+ :flow DumperOptions$FlowStyle/FLOW})
+
+(defn ^DumperOptions default-dumper-options
+ "clj-yaml 0.5.6 used SnakeYAML 1.13 which by default did *not* split long
+ lines. clj-yaml 0.6.0 upgraded to SnakeYAML 1.23 which by default *did* split
+ long lines. This ensures that generate-string uses the older behavior by
+ default, for the sake of stability, i.e. backwards compatibility."
+ []
+ (doto (DumperOptions.)
+ (.setSplitLines false)))
+
+(defn ^DumperOptions make-dumper-options
+ [& {:keys [flow-style]}]
+ (doto (default-dumper-options)
+ (.setDefaultFlowStyle (flow-styles flow-style))))
+
+(defn ^Yaml make-yaml
+ "Make a yaml encoder/decoder with some given options."
+ [& {:keys [dumper-options unsafe mark]}]
+ (let [^BaseConstructor constructor
+ (if unsafe (Constructor.)
+ (if mark (MarkedConstructor.) (SafeConstructor.)))
+ ;; TODO: unsafe marked constructor
+ dumper (if dumper-options
+ (make-dumper-options :flow-style (:flow-style dumper-options))
+ (default-dumper-options))]
+ (Yaml. constructor (Representer.) dumper)))
+
+(defrecord Marked
+ [start end unmark])
+
+(defn mark
+ "Mark some data with start and end positions."
+ [start end marked]
+ (Marked. start end marked))
+
+(defn marked?
+ "Let us know whether this piece of data is marked with source positions."
+ [m]
+ (instance? Marked m))
+
+(defn unmark
+ "Strip the source information from this piece of data, if it exists."
+ [m]
+ (if (marked? m)
+ (:unmark m)
+ m))
+
+(defprotocol YAMLCodec
+ "A protocol for things that can be coerced to and from the types
+ that snakeyaml knows how to encode and decode."
+ (encode [data])
+ (decode [data keywords]))
+
+(extend-protocol YAMLCodec
+ clj_yaml.MarkedConstructor$Marked
+ (decode [data keywords]
+ (letfn [(from-Mark [^Mark mark]
+ {:line (.getLine mark)
+ :index (.getIndex mark)
+ :column (.getColumn mark)})]
+ ;; Decode the marked data and rewrap it with its source position.
+ (mark (-> data .start from-Mark)
+ (-> data .end from-Mark)
+ (-> data .marked
+ (decode keywords)))))
+
+ clojure.lang.IPersistentMap
+ (encode [data]
+ (let [lhm (LinkedHashMap.)]
+ (doseq [[k v] data]
+ (.put lhm (encode k) (encode v)))
+ lhm))
+
+ clojure.lang.IPersistentCollection
+ (encode [data]
+ (map encode data))
+
+ clojure.lang.Keyword
+ (encode [data]
+ (name data))
+
+ java.util.LinkedHashMap
+ (decode [data keywords]
+ (letfn [(decode-key [k]
+ (if keywords
+ ;; (keyword k) is nil for numbers etc
+ (or (keyword k) k)
+ k))]
+ (into (ordered-map)
+ (for [[k v] data]
+ [(-> k (decode keywords) decode-key) (decode v keywords)]))))
+
+ java.util.LinkedHashSet
+ (decode [data keywords]
+ (into (ordered-set) data))
+
+ java.util.ArrayList
+ (decode [data keywords]
+ (map #(decode % keywords) data))
+
+ Object
+ (encode [data] data)
+ (decode [data keywords] data)
+
+ nil
+ (encode [data] data)
+ (decode [data keywords] data))
+
+
+(defn generate-string [data & opts]
+ (.dump ^Yaml (apply make-yaml opts)
+ (encode data)))
+
+(defn parse-string
+ [^String string & {:keys [unsafe mark keywords] :or {keywords true}}]
+ (decode (.load (make-yaml :unsafe unsafe :mark mark) string) keywords))
=====================================
src/java/clj_yaml/MarkedConstructor.java
=====================================
@@ -0,0 +1,61 @@
+package clj_yaml;
+
+import org.yaml.snakeyaml.constructor.Construct;
+import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.constructor.SafeConstructor;
+import org.yaml.snakeyaml.constructor.AbstractConstruct;
+import org.yaml.snakeyaml.nodes.Node;
+import org.yaml.snakeyaml.nodes.Tag;
+import org.yaml.snakeyaml.error.Mark;
+
+/* A subclass of SafeConstructor that wraps all the type-specific
+ constructors it defines with versions that mark the start and
+ end positions.
+*/
+public class MarkedConstructor extends SafeConstructor {
+ /* The types we want to wrap. */
+ public static Tag[] tags = {Tag.NULL, Tag.BOOL, Tag.INT, Tag.FLOAT,
+ Tag.BINARY, Tag.TIMESTAMP, Tag.OMAP,
+ Tag.PAIRS, Tag.SET, Tag.STR, Tag.SEQ, Tag.MAP};
+
+ public MarkedConstructor() {
+ // Make sure SafeConstructor's constructor is called first,
+ // so that we overwrite the keys that SafeConstructor sets.
+ super();
+ // Wrap all the constructors with Marking constructors.
+ for (Tag tag : tags) {
+ Construct old = this.yamlConstructors.get(tag);
+ this.yamlConstructors.put(tag, new Marking(old));
+ }
+ }
+ /* An intermediate representation of data marked with start and
+ end positions before we turn it into the nice clojure thing.
+ */
+ public static class Marked {
+ /* An object paired with start and end Marks. */
+ public Mark start;
+ public Mark end;
+ public Object marked;
+ public Marked(Mark start, Mark end, Object marked) {
+ this.start = start;
+ this.end = end;
+ this.marked = marked;
+ }
+ }
+
+ /* A wrapper around a Construct that marks source positions before calling
+ the original.
+ */
+ public class Marking extends AbstractConstruct {
+ public Construct constructor;
+ public Marking(Construct constructor) {
+ this.constructor = constructor;
+ }
+ public Object construct(Node node) {
+ return new Marked
+ (node.getStartMark(),
+ node.getEndMark(),
+ constructor.construct(node));
+ }
+ }
+}
=====================================
test/clj_yaml/core_test.clj
=====================================
@@ -1,6 +1,8 @@
(ns clj-yaml.core-test
- (:use clojure.test)
- (:use clj-yaml.core))
+ (:require [clojure.test :refer (deftest testing is)]
+ [clojure.string :as string]
+ [clj-yaml.core :refer :all])
+ (:import [java.util Date]))
(def nested-hash-yaml
"root:\n childa: a\n childb: \n grandchild: \n greatgrandchild: bar\n")
@@ -24,8 +26,8 @@ items:
- Wicked Witch of the East
")
-(def inline-list-yaml "
---- # Shopping list
+(def inline-list-yaml
+"--- # Shopping list
[milk, pumpkin pie, eggs, juice]
")
@@ -48,6 +50,9 @@ women:
(def typed-data-yaml "
the-bin: !!binary 0101")
+(def io-file-typed-data-yaml "
+!!java.io.File")
+
(def set-yaml "
--- !!set
? Mark McGwire
@@ -58,6 +63,14 @@ the-bin: !!binary 0101")
(let [parsed (parse-string "foo: bar")]
(is (= "bar" (parsed :foo)))))
+(deftest parse-hash-with-numeric-key
+ (let [parsed (parse-string "123: 456")]
+ (is (= 456 (parsed 123)))))
+
+(deftest parse-hash-with-complex-key
+ (let [parsed (parse-string "[1, 2]: 3")]
+ (is (= 3 (parsed [1, 2])))))
+
(deftest parse-nested-hash
(let [parsed (parse-string nested-hash-yaml)]
(is (= "a" ((parsed :root) :childa)))
@@ -108,14 +121,81 @@ the-bin: !!binary 0101")
(let [parsed (parse-string typed-data-yaml)]
(is (= (Class/forName "[B") (type (:the-bin parsed))))))
+(deftest disallow-arbitrary-typed-data
+ (is (thrown? org.yaml.snakeyaml.error.YAMLException
+ (parse-string io-file-typed-data-yaml))))
+
(deftest keywordized
- (binding [*keywordize* false]
- (is (= "items" (-> hashes-lists-yaml parse-string ffirst))))
- (is (= "items" (-> hashes-lists-yaml (parse-string false) ffirst))))
+ (is (= "items"
+ (-> hashes-lists-yaml
+ (parse-string :keywords false)
+ ffirst))))
+
+(deftest not-keywordized-in-lists
+ (is (every? string?
+ (-> "[{b: c, c: d}]"
+ (parse-string :keywords false)
+ first
+ keys))))
+
+(deftest marking-source-position-works
+ (let [parsed (parse-string inline-list-yaml :mark true)]
+ ;; The list starts at the beginning of line 1.
+ (is (= 1 (-> parsed :start :line)))
+ (is (= 0 (-> parsed :start :column)))
+ ;; The first item starts at the second character of line 1.
+ (is (= 1 (-> parsed unmark first :start :line)))
+ (is (= 1 (-> parsed unmark first :start :column)))
+ ;; The first item ends at the fifth character of line 1.
+ (is (= 1 (-> parsed unmark first :end :line)))
+ (is (= 5 (-> parsed unmark first :end :column)))))
+
+(deftest text-wrapping
+ (let [data
+ {:description
+ "Big-picture diagram showing how our top-level systems and stakeholders interact"}]
+ (testing "long lines of text should not be wrapped"
+ ;; clj-yaml 0.5.6 used SnakeYAML 1.13 which by default did *not* split long lines.
+ ;; clj-yaml 0.6.0 upgraded to SnakeYAML 1.23 which by default *did* split long lines.
+ ;; This test ensures that generate-string uses the older behavior by default, for the sake
+ ;; of stability, i.e. backwards compatibility.
+ (is
+ (= "{description: Big-picture diagram showing how our top-level systems and stakeholders interact}\n"
+ (generate-string data))))))
(deftest dump-opts
(let [data [{:age 33 :name "jon"} {:age 44 :name "boo"}]]
(is (= "- age: 33\n name: jon\n- age: 44\n name: boo\n"
(generate-string data :dumper-options {:flow-style :block})))
(is (= "[{age: 33, name: jon}, {age: 44, name: boo}]\n"
- (generate-string data :dumper-options {:flow-style :flow})))))
\ No newline at end of file
+ (generate-string data :dumper-options {:flow-style :flow})))))
+
+(deftest parse-time
+ (testing "clj-time parses timestamps with more than millisecond precision correctly."
+ (let [timestamp "2001-11-23 15:02:31.123456 -04:00"
+ expected 1006542151123]
+ (is (= (.getTime ^Date (parse-string timestamp)) expected)))))
+
+(deftest maps-are-ordered
+ (let [parsed (parse-string hashes-lists-yaml)
+ [first second] (parsed :items)]
+ (= (keys first) '("part_no" "descrip" "price" "quantity"))
+ (= (keys second)'("part_no" "descrip" "price" "quantity" "owners"))))
+
+
+(deftest nulls-are-fine
+ (testing "nil does not blow up"
+ (let [res (parse-string "- f:")]
+ (is (= [{:f nil}] res))
+ (is (str res)))))
+
+(deftest emoji-can-be-parsed
+ (let [yaml "{emoji: 💣}"]
+ (is (= yaml (-> yaml
+ (generate-string)
+ (parse-string)
+ (string/trim)))))
+
+ (testing "emoji in comments are OK too"
+ (let [yaml "# 💣 emoji in a comment\n42"]
+ (is (= 42 (parse-string yaml))))))
View it on GitLab: https://salsa.debian.org/clojure-team/clj-yaml-clojure/-/compare/e2bc0f16707f25fa01d2108c4257c6f24d981f96...289a838f8ad483cfc3795950b1d5b11289279eb8
--
View it on GitLab: https://salsa.debian.org/clojure-team/clj-yaml-clojure/-/compare/e2bc0f16707f25fa01d2108c4257c6f24d981f96...289a838f8ad483cfc3795950b1d5b11289279eb8
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20200901/ad21497d/attachment.html>
More information about the pkg-java-commits
mailing list