mz_pgrepr/regproc.rs
1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10#![allow(missing_docs)]
11
12pub use mz_pgrepr_consts::regproc::*;
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17
18 /// [`name`] binary searches [`NAMES`], so the table must be sorted by OID
19 /// and free of duplicate OIDs.
20 #[mz_ore::test]
21 fn names_is_sorted_by_oid() {
22 for window in NAMES.windows(2) {
23 assert!(
24 window[0].0 < window[1].0,
25 "NAMES is not sorted by OID: {} precedes {}",
26 window[0].0,
27 window[1].0,
28 );
29 }
30 }
31
32 #[mz_ore::test]
33 // `oid` scans the table, so covering every entry is quadratic and far too
34 // slow interpreted.
35 #[cfg_attr(miri, ignore)]
36 fn lookups_round_trip() {
37 for (entry_oid, entry_name) in NAMES {
38 assert_eq!(name(*entry_oid), Some(*entry_name));
39 // Overloads sharing a rendering can only resolve back to one OID,
40 // so ambiguity is the expected outcome for those.
41 match oid(entry_name) {
42 Ok(resolved) => assert_eq!(resolved, *entry_oid),
43 Err(err) => assert_eq!(err, NameLookupError::Ambiguous),
44 }
45 }
46 assert_eq!(name(0), None);
47 assert_eq!(oid("no_such_function"), Err(NameLookupError::NotFound));
48 }
49
50 /// Spot-checks the `pg_type` I/O function renderings, so a regeneration that
51 /// dropped them fails loudly.
52 #[mz_ore::test]
53 fn type_io_functions_resolve() {
54 for (func_oid, expected) in [
55 (1242, "boolin"),
56 (2436, "boolrecv"),
57 (2400, "array_recv"),
58 (2414, "textrecv"),
59 ] {
60 assert_eq!(name(func_oid), Some(expected), "regproc {func_oid}");
61 }
62 }
63}