From 8ab3322c0fecfd3e7905b8832923a8ef45b7126c Mon Sep 17 00:00:00 2001 From: Maxi Barmetler Date: Fri, 15 Mar 2024 18:00:40 +0100 Subject: [PATCH] add test_sanitize_identifier --- prost-build/src/ident.rs | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/prost-build/src/ident.rs b/prost-build/src/ident.rs index 6ccde79ef..61d9ad219 100644 --- a/prost-build/src/ident.rs +++ b/prost-build/src/ident.rs @@ -73,6 +73,67 @@ mod tests { use super::*; + #[test] + fn test_sanitize_identifier() { + assert_eq!(sanitize_identifier("as"), "r#as"); + assert_eq!(sanitize_identifier("break"), "r#break"); + assert_eq!(sanitize_identifier("const"), "r#const"); + assert_eq!(sanitize_identifier("continue"), "r#continue"); + assert_eq!(sanitize_identifier("else"), "r#else"); + assert_eq!(sanitize_identifier("enum"), "r#enum"); + assert_eq!(sanitize_identifier("false"), "r#false"); + assert_eq!(sanitize_identifier("fn"), "r#fn"); + assert_eq!(sanitize_identifier("for"), "r#for"); + assert_eq!(sanitize_identifier("if"), "r#if"); + assert_eq!(sanitize_identifier("impl"), "r#impl"); + assert_eq!(sanitize_identifier("in"), "r#in"); + assert_eq!(sanitize_identifier("let"), "r#let"); + assert_eq!(sanitize_identifier("loop"), "r#loop"); + assert_eq!(sanitize_identifier("match"), "r#match"); + assert_eq!(sanitize_identifier("mod"), "r#mod"); + assert_eq!(sanitize_identifier("move"), "r#move"); + assert_eq!(sanitize_identifier("mut"), "r#mut"); + assert_eq!(sanitize_identifier("pub"), "r#pub"); + assert_eq!(sanitize_identifier("ref"), "r#ref"); + assert_eq!(sanitize_identifier("return"), "r#return"); + assert_eq!(sanitize_identifier("static"), "r#static"); + assert_eq!(sanitize_identifier("struct"), "r#struct"); + assert_eq!(sanitize_identifier("trait"), "r#trait"); + assert_eq!(sanitize_identifier("true"), "r#true"); + assert_eq!(sanitize_identifier("type"), "r#type"); + assert_eq!(sanitize_identifier("unsafe"), "r#unsafe"); + assert_eq!(sanitize_identifier("use"), "r#use"); + assert_eq!(sanitize_identifier("where"), "r#where"); + assert_eq!(sanitize_identifier("while"), "r#while"); + assert_eq!(sanitize_identifier("dyn"), "r#dyn"); + assert_eq!(sanitize_identifier("abstract"), "r#abstract"); + assert_eq!(sanitize_identifier("become"), "r#become"); + assert_eq!(sanitize_identifier("box"), "r#box"); + assert_eq!(sanitize_identifier("do"), "r#do"); + assert_eq!(sanitize_identifier("final"), "r#final"); + assert_eq!(sanitize_identifier("macro"), "r#macro"); + assert_eq!(sanitize_identifier("override"), "r#override"); + assert_eq!(sanitize_identifier("priv"), "r#priv"); + assert_eq!(sanitize_identifier("typeof"), "r#typeof"); + assert_eq!(sanitize_identifier("unsized"), "r#unsized"); + assert_eq!(sanitize_identifier("virtual"), "r#virtual"); + assert_eq!(sanitize_identifier("yield"), "r#yield"); + assert_eq!(sanitize_identifier("async"), "r#async"); + assert_eq!(sanitize_identifier("await"), "r#await"); + assert_eq!(sanitize_identifier("try"), "r#try"); + assert_eq!(sanitize_identifier("self"), "self_"); + assert_eq!(sanitize_identifier("super"), "super_"); + assert_eq!(sanitize_identifier("extern"), "extern_"); + assert_eq!(sanitize_identifier("crate"), "crate_"); + assert_eq!(sanitize_identifier("foo"), "foo"); + assert_eq!(sanitize_identifier("bar"), "bar"); + assert_eq!(sanitize_identifier("baz"), "baz"); + assert_eq!(sanitize_identifier("0foo"), "_0foo"); + assert_eq!(sanitize_identifier("foo0"), "foo0"); + assert_eq!(sanitize_identifier("foo_"), "foo_"); + assert_eq!(sanitize_identifier("_foo"), "_foo"); + } + #[test] fn test_to_snake() { assert_eq!("foo_bar", &to_snake("FooBar"));