Skip to content

Commit

Permalink
Make ready for 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
laurmaedje committed Mar 1, 2023
1 parent b74e436 commit 8f93793
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run loom tests
env:
RUSTFLAGS: --cfg loom
run: cargo test --release loom
run: cargo test --release loom --features loom

# We use a healthy amount of unsafe, so run tests with Miri to check for UB
nightly_only:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
.DS_Store
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "ecow"
version = "0.1.0"
authors = ["Laurenz <laurmaedje@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Compact, clone-on-write vector and string."
repository = "https://github.com/typst/ecow"
keywords = ["string", "vector", "vec", "SSO", "inline", "CoW"]
description = """
Compact, clone-on-write vector and string.
"""
readme = "README.md"
license = "MIT OR Apache-2.0"
categories = ["data-structures", "no-std"]
keywords = ["string", "vector", "sso", "cow"]

[target.'cfg(loom)'.dependencies]
loom = "0.5"
loom = { version = "0.5", optional = true }
2 changes: 1 addition & 1 deletion src/string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A clone-on-write, small-string-optimized alternative to
//! [`String`][alloc::string::String]
//! [`String`][alloc::string::String].

use alloc::borrow::Cow;
use alloc::string::String;
Expand Down
2 changes: 1 addition & 1 deletion src/vec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A clone-on-write alternative to [`Vec`][alloc::vec::Vec]
//! A clone-on-write alternative to [`Vec`][alloc::vec::Vec].

use alloc::vec::Vec;
use core::alloc::Layout;
Expand Down
9 changes: 5 additions & 4 deletions tests/loom.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// Run loom tests with something like
/// ```
/// $ RUSTFLAGS="--cfg loom" cargo test --release loom
/// ```
// Run loom tests with something like
// ```
// RUSTFLAGS="--cfg loom" cargo test --release loom --features loom
// ```

#[cfg(loom)]
mod loom {
#[cfg(debug_assertions)]
Expand Down
27 changes: 11 additions & 16 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// Test with `cargo +nightly miri test` to check sanity!

extern crate alloc;

use alloc::borrow::Cow;
use alloc::boxed::Box;
use alloc::string::ToString;
use alloc::vec::Vec;
use core::mem;
use core::sync::atomic::{AtomicUsize, Ordering::*};
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Write;
use std::mem;
use std::sync::atomic::{AtomicUsize, Ordering::*};

use ecow::{eco_vec, EcoString, EcoVec};

Expand Down Expand Up @@ -42,11 +37,11 @@ fn test_mem_size() {

#[test]
fn test_vec_macro() {
assert_eq!(eco_vec![Box::new(1); 3], alloc::vec![v(1); 3]);
assert_eq!(eco_vec![Box::new(1); 3], vec![v(1); 3]);
}

#[test]
fn vec_construction() {
fn test_vec_construction() {
assert_eq!(EcoVec::<()>::default(), &[]);
assert_eq!(EcoVec::from(vec![(); 100]), vec![(); 100]);
}
Expand Down Expand Up @@ -172,7 +167,7 @@ fn test_vec_remove() {

#[test]
#[should_panic(expected = "index is out bounds (index: 4, len: 3)")]
fn vec_remove_fail() {
fn test_vec_remove_fail() {
EcoVec::from([1, 2, 3]).remove(4);
}

Expand Down Expand Up @@ -411,7 +406,7 @@ fn test_str_inline_capacity_exceeded() {
}

#[test]
fn str_clear() {
fn test_str_clear() {
let mut inline_clear = EcoString::from("foo");
inline_clear.clear();
assert_eq!(inline_clear, "");
Expand All @@ -424,7 +419,7 @@ fn str_clear() {
}

#[test]
fn str_construction() {
fn test_str_construction() {
let from_cow = EcoString::from(Cow::Borrowed("foo"));
let from_char_iter: EcoString = "foo".chars().collect();
let from_eco_string_iter: EcoString =
Expand All @@ -442,15 +437,15 @@ fn str_construction() {
}

#[test]
fn str_extend() {
fn test_str_extend() {
let mut s = EcoString::from("Hello, ");
s.extend("world!".chars());

assert_eq!(s, "Hello, world!");
}

#[test]
fn str_add() {
fn test_str_add() {
let hello = EcoString::from("Hello, ");
let world = EcoString::from("world!");

Expand All @@ -470,7 +465,7 @@ fn str_add() {
}

#[test]
fn complex() {
fn test_str_complex() {
let mut foo = EcoString::default();
foo.write_char('f').unwrap();
foo.write_str("oo").unwrap();
Expand Down
7 changes: 4 additions & 3 deletions tests/ub_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use ecow::{eco_vec, EcoVec};

// Guarding against something like:
// https://github.com/servo/rust-smallvec/issues/96 aka RUSTSEC-2018-0003
// If length isn't updated defensively then a panic when iterating could double-free a value
// If length isn't updated defensively then a panic when iterating could
// double-free a value.
#[test]
#[should_panic(expected = "Panic on next")]
fn panicky_iterator_unwinds_correctly() {
Expand All @@ -26,7 +27,7 @@ fn panicky_iterator_unwinds_correctly() {

// Guarding against something like:
// https://github.com/servo/rust-smallvec/issues/252 aka RUSTSEC-2021-0003
// size_hint should only be treated as a hint, nothing more
// size_hint should only be treated as a hint, nothing more.
#[test]
fn small_size_hint_is_fine() {
let mut v = EcoVec::new();
Expand All @@ -47,7 +48,7 @@ fn small_size_hint_is_fine() {

// Guarding against something like:
// https://github.com/Alexhuszagh/rust-stackvector/issues/2 aka RUSTSEC-2021-0048
// size_hint should only be treated as a hint, nothing more
// size_hint should only be treated as a hint, nothing more.
#[test]
fn wacky_size_hint_is_fine() {
struct IncorrectIterator(core::iter::Take<core::iter::Repeat<u8>>);
Expand Down

0 comments on commit 8f93793

Please sign in to comment.