use pdfrum::*;
const SNAPSHOT_ENUMS: &[(&str, &str, &str)] = &[
("pdfrum.txt", "pdfrum::Error", "Error"),
("pdfrum.txt", "pdfrum::Update", "Update"),
("pdfrum.txt", "pdfrum::StampPosition", "StampPosition"),
("pdfrum.txt", "pdfrum::FlattenMode", "FlattenMode"),
("pdfrum.txt", "pdfrum::Paint", "Paint"),
("pdfrum.txt", "pdfrum::Fill", "Fill"),
("pdfrum.txt", "pdfrum::LineCap", "LineCap"),
("pdfrum.txt", "pdfrum::LineJoin", "LineJoin"),
("pdfrum.txt", "pdfrum::Flattened", "Flattened"),
("pdfrum-common.txt", "pdfrum_common::DiagKind", "DiagKind"),
(
"pdfrum-common.txt",
"pdfrum_common::LimitExceeded",
"LimitExceeded",
),
("pdfrum-common.txt", "pdfrum_common::Operation", "Operation"),
("pdfrum-common.txt", "pdfrum_common::Severity", "Severity"),
("pdfrum-doc.txt", "pdfrum_doc::pdfa::Level", "PdfaLevel"),
("pdfrum-doc.txt", "pdfrum_doc::pdfa::Clause", "PdfaClause"),
("pdfrum-doc.txt", "pdfrum_doc::pdfa::Subject", "PdfaSubject"),
("pdfrum-doc.txt", "pdfrum_doc::Subtype", "Subtype"),
("pdfrum-doc.txt", "pdfrum_doc::FocusBox", "FocusBox"),
("pdfrum-doc.txt", "pdfrum_doc::form::FieldKind", "FieldKind"),
("pdfrum-doc.txt", "pdfrum_doc::ActionKind", "ActionKind"),
("pdfrum-doc.txt", "pdfrum_doc::Error", "DocError"),
("pdfrum-edit.txt", "pdfrum_edit::Error", "SaveError"),
(
"pdfrum-edit.txt",
"pdfrum_edit::FontEncoding",
"FontEncoding",
),
("pdfrum-edit.txt", "pdfrum_edit::PixelFormat", "PixelFormat"),
("pdfrum-form.txt", "pdfrum_form::Button", "Button"),
("pdfrum-form.txt", "pdfrum_form::Event", "Event"),
("pdfrum-form.txt", "pdfrum_form::Key", "Key"),
(
"pdfrum-form.txt",
"pdfrum_form::KeystrokeOutcome",
"KeystrokeOutcome",
),
("pdfrum-form.txt", "pdfrum_form::Placement", "Placement"),
("pdfrum-form.txt", "pdfrum_form::UpdateKind", "UpdateKind"),
("pdfrum-object.txt", "pdfrum_object::Error", "ObjectError"),
("pdfrum-object.txt", "pdfrum_object::Object", "Object"),
("pdfrum-page.txt", "pdfrum_page::PageObject", "PageObject"),
("pdfrum-page.txt", "pdfrum_page::Rotation", "Rotation"),
(
"pdfrum-page.txt",
"pdfrum_page::TextRenderMode",
"TextRenderMode",
),
("pdfrum-parser.txt", "pdfrum_parser::Error", "ReadError"),
("pdfrum-parser.txt", "pdfrum_parser::LoadError", "OpenError"),
("pdfrum-render.txt", "pdfrum_render::ColorMode", "ColorMode"),
("pdfrum-render.txt", "pdfrum_render::Error", "RenderError"),
("pdfrum-render.txt", "pdfrum_render::TextAa", "TextAa"),
("pdfrum-text.txt", "pdfrum_text::Error", "TextError"),
];
const DIAG_KINDS: &[DiagKind] = &[
DiagKind::AnnotSubtypeUnknown,
DiagKind::AppearanceGenerated,
DiagKind::BadStartXref,
DiagKind::BadTextRenderMode,
DiagKind::CMapCodespaceDropped,
DiagKind::CMapNameUnknown,
DiagKind::CMapOperandOverflow,
DiagKind::CMapRangeLimit,
DiagKind::CMapReversedRange,
DiagKind::CMapTableMissing,
DiagKind::CMapTruncatedCodespace,
DiagKind::CMapUsecmapDepth,
DiagKind::CMapUsecmapUnknown,
DiagKind::CMapWideMappingsDropped,
DiagKind::CidToGidStreamShort,
DiagKind::ColorKeyArrayShort,
DiagKind::ColorSpaceUnsupported,
DiagKind::DashElementClamped,
DiagKind::DashPatternDropped,
DiagKind::DefaultAppearanceMalformed,
DiagKind::DestPageUnresolved,
DiagKind::FieldSkippedNoName,
DiagKind::FieldSkippedNoType,
DiagKind::FontProgramUnreadable,
DiagKind::FontSubstitutionFailed,
DiagKind::FontWidthsTruncated,
DiagKind::FormRecursionRefused,
DiagKind::FormResourcesInvalid,
DiagKind::FunctionUnsupported,
DiagKind::GsubUnreadable,
DiagKind::HeaderOffset,
DiagKind::IccAlternateMismatch,
DiagKind::IccAlternateUsed,
DiagKind::IccStockFallback,
DiagKind::ImageBadBitDepth,
DiagKind::ImageBadDimensions,
DiagKind::ImageDecodeFailed,
DiagKind::ImageDimensionsFromCodec,
DiagKind::ImageStreamTruncated,
DiagKind::IndexedHivalClamped,
DiagKind::InkPathDropped,
DiagKind::InlineImageAbandoned,
DiagKind::InlineImageResync,
DiagKind::InlineImageUnsupported,
DiagKind::JpxColorSpaceOverride,
DiagKind::KeywordResync,
DiagKind::LegacyNamedDest,
DiagKind::LengthMismatch,
DiagKind::MalformedArray,
DiagKind::MalformedDict,
DiagKind::MaskDropped,
DiagKind::MediaBoxDefaulted,
DiagKind::MeshDecodeMalformed,
DiagKind::MeshTruncated,
DiagKind::NameTreeLimitsRepaired,
DiagKind::NameTreeMalformed,
DiagKind::NavigationCycle,
DiagKind::ObjNumMismatch,
DiagKind::ObjStmEntryDropped,
DiagKind::OperandCountMismatch,
DiagKind::OperandsDropped,
DiagKind::OptionalContentPolicyUnknown,
DiagKind::PageLabelStyleUnknown,
DiagKind::PageTreeDepthExceeded,
DiagKind::PageTreeRepaired,
DiagKind::PasswordReencoded,
DiagKind::PostScriptMalformedProc,
DiagKind::PostScriptStackAbuse,
DiagKind::QuadPointsTruncated,
DiagKind::RootRecovered,
DiagKind::ScriptFailed,
DiagKind::ScriptLimitReached,
DiagKind::ShadingUnsupported,
DiagKind::StreamInCompositeDropped,
DiagKind::StructElementDropped,
DiagKind::TextActualTextCharDropped,
DiagKind::TextActualTextUnprintable,
DiagKind::TextCharcodeZero,
DiagKind::TextCharcodesUnmapped(0),
DiagKind::TextHyphenNoPrevChar,
DiagKind::TextObjectDegenerate,
DiagKind::TextObjectDropped,
DiagKind::TextObjectDuplicate,
DiagKind::TimeLimitReached,
DiagKind::TilingRangeOverflow,
DiagKind::TilingStepInvalid,
DiagKind::TintTransformDropped,
DiagKind::ToUnicodeBlockRejected,
DiagKind::TreeDepthExceeded,
DiagKind::Type1BlendInconsistent,
DiagKind::Type1CharstringAborted,
DiagKind::Type1EncodingGlyphMissing,
DiagKind::Type1HexTruncated,
DiagKind::Type1PfbTruncated,
DiagKind::UnbalancedMarkedContent,
DiagKind::UnbalancedRestore,
DiagKind::UndecodableStream,
DiagKind::UnknownOperator,
DiagKind::XrefEntriesShifted,
DiagKind::XrefPrevLoop,
DiagKind::XrefRebuilt,
DiagKind::XrefStreamEntryDropped,
];
const SUBTYPES: &[Subtype] = &[
Subtype::Caret,
Subtype::Circle,
Subtype::FileAttachment,
Subtype::FreeText,
Subtype::Highlight,
Subtype::Ink,
Subtype::Line,
Subtype::Link,
Subtype::Movie,
Subtype::PolyLine,
Subtype::Polygon,
Subtype::Popup,
Subtype::PrinterMark,
Subtype::Redact,
Subtype::RichMedia,
Subtype::Screen,
Subtype::Sound,
Subtype::Square,
Subtype::Squiggly,
Subtype::Stamp,
Subtype::StrikeOut,
Subtype::Text,
Subtype::ThreeD,
Subtype::TrapNet,
Subtype::Underline,
Subtype::Unknown,
Subtype::Watermark,
Subtype::Widget,
Subtype::XfaWidget,
];
const ACTION_KINDS: &[ActionKind] = &[
ActionKind::GoTo,
ActionKind::GoTo3DView,
ActionKind::GoToE,
ActionKind::GoToR,
ActionKind::Hide,
ActionKind::ImportData,
ActionKind::JavaScript,
ActionKind::Launch,
ActionKind::Movie,
ActionKind::Named,
ActionKind::Rendition,
ActionKind::ResetForm,
ActionKind::SetOcgState,
ActionKind::Sound,
ActionKind::SubmitForm,
ActionKind::Thread,
ActionKind::Trans,
ActionKind::Unknown,
ActionKind::Uri,
];
const KEYS: &[Key] = &[
Key::A,
Key::Backspace,
Key::Control,
Key::Delete,
Key::Down,
Key::End,
Key::Escape,
Key::Home,
Key::Insert,
Key::Left,
Key::Newline,
Key::Other(0),
Key::PageDown,
Key::PageUp,
Key::Return,
Key::Right,
Key::Shift,
Key::Space,
Key::Tab,
Key::Unknown,
Key::Up,
Key::Y,
Key::Z,
];
fn argb() -> Argb {
Argb {
a: 0,
r: 0,
g: 0,
b: 0,
}
}
fn generated_ap() -> GeneratedAp {
GeneratedAp {
stream: Vec::new(),
bbox: Rect::new(0.0, 0.0, 1.0, 1.0),
matrix: Affine::IDENTITY,
resources: Dict::new(),
rect_override: None,
as_override: None,
}
}
fn keystroke() -> Keystroke {
Keystroke {
change: String::new(),
value: String::new(),
selection_start: 0,
selection_end: 0,
}
}
fn origin() -> Point {
Point::new(0.0, 0.0)
}
fn every_object_variant(obj: &Object) {
match obj {
Object::Array(_)
| Object::Bool(_)
| Object::Dict(_)
| Object::Int(_)
| Object::Name(_)
| Object::Null
| Object::Real(_)
| Object::Ref(_)
| Object::Str(_)
| Object::Stream(_) => {}
}
}
fn every_page_object_variant(obj: &PageObject) {
match obj {
PageObject::Form(_)
| PageObject::Image(_)
| PageObject::Path(_)
| PageObject::Shading(_)
| PageObject::Text(_) => {}
}
}
fn construct_facade_variants() -> usize {
let mut n = 0;
let _ = Error::WrongPassword;
let _ = Error::Open(OpenError::NotPdf);
let _ = Error::Read(ReadError::NoCatalog);
let _ = Error::Render(RenderError::TargetEmpty {
width: 0,
height: 0,
});
let _ = Error::Doc(DocError::NoCatalog);
let _ = Error::Save(SaveError::BadPageRange);
let _ = Error::Text(TextError::CharIndexOutOfRange {
index: CharIndex::new(0),
len: 0,
});
let _ = Error::Io(std::io::Error::other("construct"));
let _ = Error::Limit(LimitExceeded::RenderPixels {
width: 0,
height: 0,
allowed: 0,
});
n += 9;
let _ = Update::Incremental;
let _ = Update::Rewrite;
n += 2;
let _ = StampPosition::Center;
let _ = StampPosition::TopLeft;
let _ = StampPosition::TopRight;
let _ = StampPosition::BottomLeft;
let _ = StampPosition::BottomRight;
n += 5;
let _ = FlattenMode::Display;
let _ = FlattenMode::Print;
let _ = Flattened::Done;
let _ = Flattened::NothingToDo;
n += 4;
let stroke = Stroke::new(Color::BLACK, 1.0);
let _ = Paint::Fill(Color::BLACK);
let _ = Paint::Stroke(stroke.clone());
let _ = Paint::FillStroke(Color::BLACK, stroke);
let _ = Fill::NonZero;
let _ = Fill::EvenOdd;
n += 5;
let _ = LineCap::Butt;
let _ = LineCap::Round;
let _ = LineCap::Square;
let _ = LineJoin::Miter;
let _ = LineJoin::Round;
let _ = LineJoin::Bevel;
n += 6;
n
}
fn construct_common_variants() -> usize {
let mut n = 0;
let _ = LimitExceeded::RenderPixels {
width: 0,
height: 0,
allowed: 0,
};
let _ = LimitExceeded::Time {
budget: std::time::Duration::ZERO,
during: Operation::Open,
page: None,
};
let _ = LimitExceeded::Stopped {
during: Operation::Open,
page: None,
};
n += 3;
let _ = Operation::Open;
let _ = Operation::PageLoad;
let _ = Operation::Interpret;
let _ = Operation::Render;
let _ = Operation::Extract;
let _ = Operation::Script;
n += 6;
n += DIAG_KINDS.len();
let _ = Severity::Recovered;
let _ = Severity::Suspicious;
n += 2;
n
}
fn construct_doc_variants() -> usize {
let mut n = 0;
n += SUBTYPES.len();
let _ = FocusBox::None;
let _ = FocusBox::Inflated;
let _ = FocusBox::Rect(Rect::new(0.0, 0.0, 1.0, 1.0));
n += 3;
let _ = FieldKind::Button;
let _ = FieldKind::Check;
let _ = FieldKind::Combo;
let _ = FieldKind::List;
let _ = FieldKind::Radio;
let _ = FieldKind::Signature;
let _ = FieldKind::Text;
n += 7;
n += ACTION_KINDS.len();
let _ = DocError::NoCatalog;
let _ = DocError::Unresolved(ObjRef::new(1, 0));
n += 2;
let _ = pdfrum::PdfaLevel::A1b;
let _ = pdfrum::PdfaLevel::A2b;
n += 2;
let _ = pdfrum::PdfaSubject::Document;
let _ = pdfrum::PdfaSubject::Catalog;
let _ = pdfrum::PdfaSubject::Page(0);
let _ = pdfrum::PdfaSubject::Object(pdfrum::ObjRef::new(1, 0));
let _ = pdfrum::PdfaSubject::Resource {
page: 0,
name: String::new(),
};
n += 5;
let _ = pdfrum::PdfaClause::FontNotEmbedded;
let _ = pdfrum::PdfaClause::FontSubsetIncomplete;
let _ = pdfrum::PdfaClause::FontEncodingInvalid;
let _ = pdfrum::PdfaClause::Encrypted;
let _ = pdfrum::PdfaClause::JavaScript;
let _ = pdfrum::PdfaClause::ForbiddenAction;
let _ = pdfrum::PdfaClause::EmbeddedMultimedia;
let _ = pdfrum::PdfaClause::XmpMissing;
let _ = pdfrum::PdfaClause::XmpMalformed;
let _ = pdfrum::PdfaClause::XmpIdentificationMissing;
let _ = pdfrum::PdfaClause::XmpIdentificationMismatch;
let _ = pdfrum::PdfaClause::XmpInfoMismatch;
let _ = pdfrum::PdfaClause::OutputIntentMissing;
let _ = pdfrum::PdfaClause::OutputIntentProfileMissing;
let _ = pdfrum::PdfaClause::AnnotationFlagsIllegal;
let _ = pdfrum::PdfaClause::AnnotationSubtypeForbidden;
let _ = pdfrum::PdfaClause::AnnotationAppearanceMissing;
let _ = pdfrum::PdfaClause::ExternalContentReference;
let _ = pdfrum::PdfaClause::Transparency;
let _ = pdfrum::PdfaClause::DeviceColorWithoutOutputIntent;
let _ = pdfrum::PdfaClause::OptionalContent;
let _ = pdfrum::PdfaClause::EmbeddedFile;
let _ = pdfrum::PdfaClause::LzwFilter;
let _ = pdfrum::PdfaClause::JpxFilter;
n += 24;
n
}
fn construct_edit_variants() -> usize {
let mut n = 0;
let _ = SaveError::BadNupParams;
let _ = SaveError::BadPageRange;
let _ = SaveError::EncryptedSaveUnsupported;
let _ = SaveError::PasswordNotText;
let _ = SaveError::NoEntropy;
let _ = SaveError::Io(std::io::Error::other("construct"));
let _ = SaveError::NoDestinationCatalog;
let _ = SaveError::Object(ObjectError::UnresolvedRef(ObjRef::new(1, 0)));
let _ = SaveError::PageIndexOutOfRange(PageIndex::from(0u32));
let _ = SaveError::Subset(String::new());
let _ = SaveError::UnrecognisedFontProgram;
let _ = SaveError::EmptyFontProgram;
let _ = SaveError::EmptyToUnicodeCMap;
let _ = SaveError::BadCidToGidMap(3);
let _ = SaveError::UnrecognisedImageData;
let _ = SaveError::EmptyImage;
let _ = SaveError::ImageDataLength {
expected: 0,
found: 0,
};
let _ = SaveError::MissingGlyph(MissingGlyph {
character: 'a',
offset: 0,
});
let _ = SaveError::InlinePage(PageIndex::from(0u32));
n += 19;
let _ = FontEncoding::Simple;
let _ = FontEncoding::Composite;
n += 2;
let _ = PixelFormat::Gray8;
let _ = PixelFormat::Rgb8;
let _ = PixelFormat::Cmyk8;
let _ = PixelFormat::Rgba8;
let _ = PixelFormat::Mask1;
n += 5;
n
}
fn construct_form_variants() -> usize {
let mut n = 0;
let _ = Button::Left;
let _ = Button::Right;
n += 2;
let none = Modifiers::NONE;
let at = origin();
let _ = Event::MouseMove {
at,
modifiers: none,
};
let _ = Event::MouseDown {
button: Button::Left,
at,
modifiers: none,
};
let _ = Event::MouseUp {
button: Button::Left,
at,
modifiers: none,
};
let _ = Event::DoubleClick {
at,
modifiers: none,
};
let _ = Event::MouseWheel {
at,
delta: (0, 0),
modifiers: none,
};
let _ = Event::Focus {
at,
modifiers: none,
};
let _ = Event::KeyDown {
key: Key::Tab,
modifiers: none,
};
let _ = Event::Char {
ch: 'a',
modifiers: none,
};
n += 8;
n += KEYS.len();
let _ = KeystrokeOutcome::Accept(keystroke());
let _ = KeystrokeOutcome::Reject;
n += 2;
let _ = Placement::Above;
let _ = Placement::Below;
n += 2;
let _ = UpdateKind::ActionRequested {
action: Box::new(Action::new(Dict::new())),
modifiers: none,
};
let _ = UpdateKind::FocusChanged {
from: None,
to: None,
};
let _ = UpdateKind::LiveEdit(Box::new(generated_ap()));
let _ = UpdateKind::Regenerated(Box::new(generated_ap()));
let _ = UpdateKind::RevertedToFileAppearance;
n += 5;
n
}
fn construct_object_variants() -> usize {
let mut n = 0;
let _ = ObjectError::RefLoop(ObjRef::new(1, 0));
let _ = ObjectError::SpanOutOfBounds {
start: 0,
end: 0,
len: 0,
};
let _ = ObjectError::UnresolvedRef(ObjRef::new(1, 0));
n += 3;
let objects: &[Object] = &[
Object::Null,
Object::Bool(false),
Object::Int(0),
Object::Real(0.0),
Object::Dict(Dict::new()),
Object::Ref(ObjRef::new(1, 0)),
];
for o in objects {
every_object_variant(o);
}
n += 10;
n
}
fn construct_page_variants() -> usize {
let mut n = 0;
let path = PathBuilder::rect(Rect::new(0.0, 0.0, 1.0, 1.0)).build();
let text = TextBuilder::new(b"a".as_slice(), ObjRef::new(1, 0), 12.0).build();
let image = ImageBuilder::at(ObjRef::new(1, 0), Rect::new(0.0, 0.0, 1.0, 1.0)).build();
every_page_object_variant(&path);
every_page_object_variant(&text);
every_page_object_variant(&image);
n += 5;
let _ = Rotation::None;
let _ = Rotation::Quarter;
let _ = Rotation::Half;
let _ = Rotation::ThreeQuarter;
n += 4;
let modes: &[TextRenderMode] = &[
TextRenderMode::Fill,
TextRenderMode::Stroke,
TextRenderMode::FillStroke,
TextRenderMode::Invisible,
TextRenderMode::FillClip,
TextRenderMode::StrokeClip,
TextRenderMode::FillStrokeClip,
TextRenderMode::Clip,
];
n += modes.len();
n
}
fn construct_parser_variants() -> usize {
let mut n = 0;
let _ = ReadError::Cycle(ObjRef::new(1, 0));
let _ = ReadError::NoCatalog;
let _ = ReadError::NoObject(0);
let _ = ReadError::NoPage(PageIndex::from(0u32));
let _ = ReadError::TooDeep(0);
let _ = ReadError::Unresolved(ObjRef::new(1, 0));
let _ = ReadError::XrefBroken;
let _ = ReadError::Limit(LimitExceeded::RenderPixels {
width: 0,
height: 0,
allowed: 0,
});
n += 8;
let _ = OpenError::Broken(String::new());
let _ = OpenError::NotPdf;
let _ = OpenError::UnsupportedEncryption(String::new());
let _ = OpenError::WrongPassword;
let _ = OpenError::Limit(LimitExceeded::RenderPixels {
width: 0,
height: 0,
allowed: 0,
});
n += 5;
n
}
fn construct_render_and_text_variants() -> usize {
let mut n = 0;
let _ = ColorMode::Alpha;
let _ = ColorMode::Forced(ColorScheme {
path_fill: argb(),
path_stroke: argb(),
text_fill: argb(),
text_stroke: argb(),
});
let _ = ColorMode::Gray;
let _ = ColorMode::Normal;
n += 4;
let _ = RenderError::TargetEmpty {
width: 0,
height: 0,
};
let _ = RenderError::TargetTooLarge {
width: 0,
height: 0,
limit: 0,
};
let _ = RenderError::Limit(LimitExceeded::RenderPixels {
width: 0,
height: 0,
allowed: 0,
});
n += 3;
let _ = TextAa::Grayscale;
let _ = TextAa::LcdSubpixel;
let _ = TextAa::None;
n += 3;
let _ = TextError::CharIndexOutOfRange {
index: CharIndex::new(0),
len: 0,
};
n += 1;
n
}
fn construct_default_feature_variants() -> usize {
construct_facade_variants()
+ construct_common_variants()
+ construct_doc_variants()
+ construct_edit_variants()
+ construct_form_variants()
+ construct_object_variants()
+ construct_page_variants()
+ construct_parser_variants()
+ construct_render_and_text_variants()
}
#[cfg(feature = "javascript")]
fn construct_script_feature_variants() -> usize {
let _ = ScriptStop::LimitReached;
let _ = ScriptStop::Threw(String::new());
let lines: &[TranscriptLine] = &[
TranscriptLine::Alert {
title: String::new(),
message: String::new(),
icon: 0,
button: 0,
},
TranscriptLine::Beep(0),
TranscriptLine::Response {
question: String::new(),
title: String::new(),
default_value: String::new(),
label: String::new(),
password: false,
},
TranscriptLine::MailMsg {
ui: false,
to: String::new(),
cc: String::new(),
bcc: String::new(),
subject: String::new(),
body: String::new(),
},
TranscriptLine::Print {
ui: false,
start: 0,
end: 0,
silent: false,
shrink_to_fit: false,
print_as_image: false,
reverse: false,
annotations: false,
},
TranscriptLine::SubmitForm {
url: String::new(),
data: Vec::new(),
},
TranscriptLine::GotoPage(0),
TranscriptLine::NamedAction(String::new()),
TranscriptLine::ConsolePrintln(String::new()),
TranscriptLine::FunctionAlert {
caller: String::new(),
message: String::new(),
},
];
2 + lines.len()
}
#[test]
fn facade_enum_variants_are_constructible() {
assert_eq!(construct_facade_variants(), 9 + 2 + 5 + 4 + 5 + 6);
}
#[test]
fn common_enum_variants_are_constructible() {
assert_eq!(construct_common_variants(), 3 + 6 + DIAG_KINDS.len() + 2);
}
#[test]
fn doc_enum_variants_are_constructible() {
assert_eq!(
construct_doc_variants(),
SUBTYPES.len() + 3 + 7 + ACTION_KINDS.len() + 2 + 2 + 5 + 24
);
}
#[test]
fn edit_enum_variants_are_constructible() {
assert_eq!(construct_edit_variants(), 19 + 2 + 5);
}
#[test]
fn form_enum_variants_are_constructible() {
assert_eq!(construct_form_variants(), 2 + 8 + KEYS.len() + 2 + 2 + 5);
}
#[test]
fn object_enum_variants_are_constructible() {
assert_eq!(construct_object_variants(), 3 + 10);
}
#[test]
fn page_enum_variants_are_constructible() {
assert_eq!(construct_page_variants(), 5 + 4 + 8);
}
#[test]
fn parser_enum_variants_are_constructible() {
assert_eq!(construct_parser_variants(), 8 + 5);
}
#[test]
fn render_and_text_enum_variants_are_constructible() {
assert_eq!(construct_render_and_text_variants(), 4 + 3 + 3 + 1);
}
#[test]
fn every_public_enum_variant_is_constructible_from_the_facade() {
let constructed = construct_default_feature_variants();
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let mut derived = 0;
for &(file, path, _) in SNAPSHOT_ENUMS {
let text = std::fs::read_to_string(root.join("docs/api-baseline").join(file))
.expect("api-baseline snapshot is readable");
let prefix = format!("pub {path}::");
let mut collecting = false;
for line in text.lines() {
if line.contains(&format!("pub enum {path}")) {
collecting = true;
continue;
}
if !collecting {
continue;
}
if let Some(rest) = line.strip_prefix(&prefix) {
if !rest.split_once("::").is_some_and(|(head, _)| {
head.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
}) {
derived += 1;
}
continue;
}
if line.contains("pub enum ")
|| line.starts_with("pub struct ")
|| line.starts_with("impl ")
|| line.starts_with("pub fn ")
|| line.starts_with("pub const ")
|| line.starts_with("pub type ")
|| line.starts_with("pub mod ")
|| line.starts_with("pub use ")
{
collecting = false;
}
}
}
assert_eq!(
constructed, derived,
"constructed {constructed} default-feature variants, snapshots derive {derived}; \
SNAPSHOT_ENUMS is the derivation index — add a construction when a variant lands"
);
assert_eq!(constructed, 357, "default-feature variant count");
assert_eq!(SNAPSHOT_ENUMS.len(), 41, "default-feature enum count");
}
#[test]
#[cfg(feature = "javascript")]
fn every_script_enum_variant_is_constructible_from_the_facade() {
assert_eq!(construct_script_feature_variants(), 12);
}